martes, 26 de noviembre de 2013

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

tcpdump

sudo tcpdump -A -w tcpdump.log -i eth0 dst 10.1.0.1 and port 80

martes, 9 de julio de 2013

ruby code after bash pipe

ruby -n -a -e 'puts "first field: #{$F[0]}, whole line: #{$_}"'

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

jueves, 9 de mayo de 2013

grep regex

grep -o 'whatever\([a-z_]\+\)whatever'

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