diff options
| author | wukong <wukong@longaeva> | 2026-04-10 23:46:12 -0700 |
|---|---|---|
| committer | wukong <wukong@longaeva> | 2026-04-10 23:46:12 -0700 |
| commit | 4c4eb1bd8f003b3b57707badd2dd089ed193a896 (patch) | |
| tree | 15b62907fffd70c46a9b4369df93ab33c6aa88ac /sum1.awk | |
| parent | e7d1781578e846a7b1d634cd43c8fab00a67b883 (diff) | |
renamed fir window generators;
minor edits to whitespace and comments for more consistent style;
Diffstat (limited to '')
| -rw-r--r-- | sum1.awk | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -5,15 +5,35 @@ # output: sum of each column # missing entries are treated as zeros -BEGIN { OFS = FS } -{ - if (NF > nf_max) - nf_max = NF +function isnum(n) { + sign = "[+-]?" + decimal = "[0-9]+[.]?[0-9]*" + fraction = "[.][0-9]+" + exponent = "([Ee]" sign "[0-9]+)?" + number = "^" sign "(" decimal "|" fraction ")" exponent "$" + return n ~ number +} + + +BEGIN { + OFS = FS +} + + +NR == 1 { + for (i=1; i<=NF; i++) + isnum($i) ? header[i] = "col" i : header[i] = $i +} + + +NF > 0 { + (NF > nf_max) ? nf_max = NF : nf_max = nf_max for (i=1; i<=NF; i++) sum[i] += $i } + END { for (i=1; i<=nf_max; i++) { printf(OFMT, sum[i]) |
