frequently used awk

To print first column of a file
awk < file '{print $1}'

To find the sum of first column elements
awk '{total=total+$1} END {print total}' filename

To print all lines sorted by taking 3rd column as reference
awk '{print $3 $0}' < file | sort


awk fields from two different files
 pr -m -t -s\  file1 file2 | gawk '{print $4,$5,$6,$1}'
 

No comments:

Post a Comment