Wednesday, February 6, 2013

awk survival kit


look for a string in the 28th colon in a tsv:

awk -F$'\t' '{if($28 == "popcorn") print $0;}' toto.tsv
awk -F$'\t' '{print $18}' wm_marchand_Data.txt | sort -u
awk -F$'\t' '{print $2 "\t" $1}' sb.txt

for special caracters:
iconv -f ISO-8859-1 -t utf8 ri_thesaurus_v2_Data_LG161___.txt > ri_thesaurus_v2_Data_LG161____.txt
iconv -f utf8 -t ISO-8859-1//TRANSLIT lbm-ko-full-201806.csv > lbm-ko-full-201806-ISO8859.csv
  • keep numbers after = in the output
awk -F$' ' '{print $11}' noc.log  | sed -r 's/.*=([0-9]+)/\1/g'
  • keep only numbers
awk -F':' '{print $3}'  1300-siren.txt | sed -r 's/[^0-9]//g'
  • sort by full number
awk -F$' ' '{print $11}' noc.log  |sed -r 's/.*=([0-9]+)/\1/g' | sort -k1,1n > noc-out.log

  • grep -P "\t8" file1.txt |awk -F$'\t' '{print $1}' |while read -r x; do grep "$x" file2.txt; done
  • to find out swap
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done| awk -F$' ' '{print $2}'  |sort  -k1,1n

.
.

No comments: