[awk] Sum numbers from standard input

Created on November 30, 2026

You can pipe a list of numbers to awk and add them up one line at a time. Save these numbers in dummy.txt.

10
20
50
20

In this example, cat writes the file to standard output. awk reads it through the pipe, adds the first field on each line to total, and prints the sum after it has read all the input.

cat dummy.txt | awk '{ total += $1 } END { print total }'
100
awk