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

### 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 > nf_max)
        nf_max = NF
}

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