Friday, February 27, 2009

awk command to sum a column

bbs-list file

aardvark 555-5553 1200/300 B
alpo-net 555-3412 2400/1200/300 A
barfly 555-7685 1200/300 A
bites 555-1675 2400/1200/300 A
camelot 555-0542 300 C
core 555-2912 1200/300 C
fooey 555-1234 2400/1200/300 B
foot 555-6699 1200/300 B
macfoo 555-6480 1200/300 A
sdace 555-3430 2400/1200/300 A
sabafoo 555-2127 1200/300 C

awk command for sum of a column

cat bbs-list | cut -f3 -d" "|cut -f1 -d"/"| awk '{ s=$0+s} END {print s}'

SPECIFYING A FIELD SEPARATOR IN AWk

awk -F: ’{ print $1 }’ /etc/passwd | sort

No comments: