Awk one-liner for adding a bunch of numbers


If the numbers are in a file:
awk '{tot=tot+$1} END {print tot}' File1

To sum the output from another command (assumes numbers to be added are in fourth column):
some-command | awk '{tot=tot+$4} END {print tot}

If the numbers are floats, you can dress up the output a bit if desired:

awk '{tot=tot+$1} END {printf "%8.2f\n",tot}' File1

05/26/2011