diff options
Diffstat (limited to 'sum3.awk')
| -rw-r--r-- | sum3.awk | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -1,8 +1,16 @@ +#!/usr/bin/awk -f + ### sum3.awk, print sums of numeric columns # input: rows of integers and strings # output: sums of numeric columns # assumes every line has same layout + +function isnum(n) { + return n ~ /^[+-]?[0-9]+$/ +} + + NR==1 { nfld = NF for (i=1; i<=NF; i++) @@ -17,15 +25,8 @@ NR==1 { END { for (i=1; i<=nfld; i++) { - if (numcol[i]) - printf("%g", sum[i]) - else - printf("--") + (numcol[i]) ? printf("%g", sum[i]) : printf("--") printf(i < nfld ? " " : "\n") } } -function isnum(n) { - return n ~ /^[+-]?[0-9]+$/ -} - |
