Sum a Column With awk
Aggregate numbers in a column without a spreadsheet.
Run awk '{s+=$1} END {print s}' file to add up the first column.
01Command
Command
$ awk '{s+=$1} END {print s}' numbers.txt02What it does
awk splits each line into fields and accumulates a running total in END, so summing, averaging or counting a column of a text file is a one-liner that scales to millions of rows. It is scriptable in a way that a GUI spreadsheet is not.
03Risk
!Warning: awk treats non-numeric fields as zero; clean the input or validate columns first if data is mixed.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- gawk.1.en.html manual page (Debian bookworm)Evidence: Documents awk fields, arithmetic and END blocks for column aggregation.
Last verified: 2026-10-13 · Category: Developer