AWK
$0: the whole line
$1, $2, ... : cells in a line
FS: field separator, defaults to ' '
RS: record separator, defaults to '\n'
NF: number of field
NR: number of record
OFS: output field separator, defaults to ' '
ORS: output record separator, defaults to '\n'
awk -F '[[:space:]+]'
awk -F ':'
awk -F '[ ,]+'
awk '{print "a" "b" "c" $1}'
awk '{print $3" "$7}'
awk '{if(NR>=20 && NR<=30){print $1}}'
awk 'if($0~/pattern/){}'
awk '/pattern/{}'
awk 'if($0 !~ /pattern/){}'
awk '($1=="root"){}'
awk 'BEGIN{print a++,++a}'
awk 'BEGIN{a="20b4";print a++,++a}'
awk 'BEGIN{count=0;} {count++;} END{print count;}'
awk -f code.txt data.txt
awk 'BEGIN{FS="\n";RS=""}'
awk '{total += $1; count++} END {print total/count}' log.txt
bash
References
