summaryrefslogtreecommitdiff
path: root/sum1.awk
blob: 8617e500dd970bed17fae4fdcc45779718fd4a2c (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("%.18g", sum[i])
        printf((i < nf_max) ? OFS : ORS)
    }
}