diff options
Diffstat (limited to '')
| -rw-r--r-- | sum2.awk | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -1,16 +1,18 @@ +#!/usr/bin/awk -f + ### sum2.awk, print column sums # check that each line has the same number of fields as line one -NR==1 { nfld = NF } +NR==1 { nf_max = NF } { for (i=1; i<=NF; i++) sum[i] += $i - if (NF != nfld) - print "line " NR " has " NF " entries, not " nfld + if (NF != nf_max) + print "line " NR " has " NF " entries, not " nf_max } END { for (i=1; i<=NF; i++) - printf("%g%s", sum[i], i < nfld ? " " : "\n") + printf("%g%s", sum[i], i < nf_max ? " " : "\n") } |
