↑ ↓ select, Enter open, Esc close

Sum the numbers in a column with awk

Adjust the values, the command updates live
user@server
awk -v c=10 '{s += $c} END {print s}' /var/www/vhosts/system/example.com/logs/access_ssl_log

Sums the values of the given column across all lines, with columns separated by spaces or tabs. In the example, column 10 of an access log in combined format yields the bytes served. Non-numeric values such as - count as 0.

Note: A pipe works instead of a file too, for example du -s * | awk .... For other delimiters, add -F';'.

Also searched as

  • awk sum column
  • add up numbers in a column linux
  • sum values in a file command line

Related one-liners

All in Text processing

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.