sed -i '1iline text at the beginning' hello.txt
http://superuser.com/questions/246837/how-do-i-add-text-to-the-beginning-of-a-file-in-bash
miércoles, 18 de diciembre de 2013
martes, 26 de noviembre de 2013
Test if string is a number in Ruby
def is_number?(object)
true if Float(object) rescue false
end
(http://stackoverflow.com/questions/5661466/test-if-string-is-a-number-in-ruby-on-rails)
viernes, 9 de agosto de 2013
strace for parent and threads and output to files
sudo strace -tt -s 1024 -o strace.log -ffv -p {pid}
miércoles, 7 de agosto de 2013
martes, 9 de julio de 2013
viernes, 7 de junio de 2013
grep output only part of matching regex
$ echo 'ETag: "ae02fff4e2395982747582496ada225d"'
ETag: "ae02fff4e2395982747582496ada225d"
#I want just the ETag value:
$ echo 'ETag: "ae02fff4e2395982747582496ada225d"' |grep -oP '(?<=ETag: ")\w+(?=")'
ae02fff4e2395982747582496ada225d
Ref: http://unix.stackexchange.com/questions/13466/can-grep-output-only-specified-groupings-that-match
ETag: "ae02fff4e2395982747582496ada225d"
#I want just the ETag value:
$ echo 'ETag: "ae02fff4e2395982747582496ada225d"' |grep -oP '(?<=ETag: ")\w+(?=")'
ae02fff4e2395982747582496ada225d
Ref: http://unix.stackexchange.com/questions/13466/can-grep-output-only-specified-groupings-that-match
jueves, 9 de mayo de 2013
jueves, 17 de enero de 2013
sort -u like awk for few items and many dups
| awk '{a[$0]=1} END{for (k in a) print k}'
Performance test:
# create a file with few items and many dups
$ for i in {1..1000000}; do printf "a\nb\nc\n" >> few_items_many_dups.txt; done
# sort uniq using awk
$ time cat few_items_many_dups.txt | awk '{a[$0]=1} END{for (k in a) print k}' > few_items_many_dups.txt.awk_sortuniq
real 0m1.291s
# sort uniq using sort -u
$ time cat few_items_many_dups.txt | sort -u > few_items_many_dups.txt.sortuniq
real 0m36.726s
Performance test:
# create a file with few items and many dups
$ for i in {1..1000000}; do printf "a\nb\nc\n" >> few_items_many_dups.txt; done
# sort uniq using awk
$ time cat few_items_many_dups.txt | awk '{a[$0]=1} END{for (k in a) print k}' > few_items_many_dups.txt.awk_sortuniq
real 0m1.291s
# sort uniq using sort -u
$ time cat few_items_many_dups.txt | sort -u > few_items_many_dups.txt.sortuniq
real 0m36.726s
Suscribirse a:
Entradas (Atom)