Sum a column
Accumulate a numeric column and print total
awk '{sum += $4} END {print sum}' access.log
- tool
- awk15 commands
More awk commands
-
awk '/START/,/END/' file.txtRange pattern: include lines from START to END inclusive
-
awk 'NR>1 {print $1, $2}' data.csvProcess all lines except the first (header)
-
awk '{count[$1]++} END {for (k in count) print count[k], k}' access.log | sort -rnFrequency count of the first field (e.g. IP addresses)
-
awk '{print $NF}' file.txtNF holds the number of fields; $NF is the last field
-
awk '$2 > 500 && $5 == "POST"' access.logPrint lines where field 2 > 500 AND field 5 is POST