summaryrefslogtreecommitdiff
path: root/sum1.awk
blob: 8f1419bd5f1635cd5053c610e557e37e3f471e0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/awk -f

### sum1.awk, print column sums
# input: rows of numbers
# output: sum of each column
#   missing entries are treated as zeros

BEGIN { OFS = FS }

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

END {
    for (i=1; i<=nf_max; i++) {
        printf(OFMT, sum[i])
        printf((i < nf_max) ? OFS : ORS)
    }
}