Wednesday, January 6, 2016

how to use AWK to calculate thru lines/columns of a file



sometimes useful; calculate entries, sum of one column and average.

$ cat example.txt
1;line1
2;line2
3;line3

$cat example.txt |awk 'BEGIN { FS=";";sum=0;count=0 } {sum=sum+$1;count=count+1} END{printf("%d %d %d", sum,count,(sum/count))}'

6 3 2