## Using AWK to generate a sum / add up all the numbers in a column

This is another of those things I can never remember, and so I've finally made myself a note!.

cat authors.txt | awk 'BEGIN {FS = " "} ; {sum+=$1} END {print sum}'

This will add up and print out all of the numbers in the first column of authors.txt.

sum starts out as 0. For each row, the value of $1 is added to sum. At the end of the input (file / STDIN) we print the value of sum.