Sum a column with awk

Bash

Adds the third field of every line and prints the total, ignoring anything non-numeric.

awk -F',' '{ total += $3 } END { print total }' sales.csv

# Skipping a header row:
awk -F',' 'NR > 1 { total += $3 } END { printf "%.2f\n", total }' sales.csv

More in Text Processing

Random picks