summaryrefslogtreecommitdiff
path: root/sum2.awk
blob: 0b2aad3ad9adb36bfaf47f1ff6edf1dd21a21250 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
### sum2.awk, print column sums
# check that each line has the same number of fields as line one

NR==1 { nfld = NF }

{
    for (i=1; i<=NF; i++)
        sum[i] += $i
    if (NF != nfld)
        print "line " NR " has " NF " entries, not " nfld
}

END {
    for (i=1; i<=NF; i++)
        printf("%g%s", sum[i], i < nfld ? "  " : "\n")
}