Awk

Single quote in awk
[sourcecode]awk ‘{ print ",", foo$1foo }’ foo="’" file[/sourcecode]

Delimiter in awk -F, and the last column $NF
cat /etc/passwd | awk -F: ‘{print $5}’ | awk -F, ‘{print $NF}’

Field separator
[sourcecode]awk ‘{ FS = "\t"; print $3 }’ file[/sourcecode]

Line number: NR

Sum the number in a column, say column 1
[sourcecode]awk ‘{ sum+=$1 } END {print sum}’ file[/sourcecode]

Leave a Reply