summaryrefslogtreecommitdiff
path: root/sum1.awk
blob: 02b7d6a6c60e985a2fb1abab8154d79fdd7e2fd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
### sum1.awk, print column sums
# input: rows of numbers
# output: sum of each column
#   missing entries are treated as zeros

{
    for (i=1; i<=NF; i++)
        sum[i] += $i
    if (NF > maxfld)
        maxfld = NF
}

END {
    for (i=1; i<=maxfld; i++) {
        printf("%g", sum[i])
        if (i < maxfld)
            printf("  ")
        else
            printf("\n")
    }
}