summaryrefslogtreecommitdiff
path: root/sum2.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
committerwukong <wukong@longaeva>2026-04-10 23:46:12 -0700
commit4c4eb1bd8f003b3b57707badd2dd089ed193a896 (patch)
tree15b62907fffd70c46a9b4369df93ab33c6aa88ac /sum2.awk
parente7d1781578e846a7b1d634cd43c8fab00a67b883 (diff)
renamed fir window generators;
minor edits to whitespace and comments for more consistent style;
Diffstat (limited to '')
-rw-r--r--sum2.awk19
1 files changed, 14 insertions, 5 deletions
diff --git a/sum2.awk b/sum2.awk
index 694c047..4fcf3b6 100644
--- a/sum2.awk
+++ b/sum2.awk
@@ -3,18 +3,27 @@
### sum2.awk, print column sums
# check that each line has the same number of fields as line one
-BEGIN { OFS = FS }
-NR == 1 { nf_max = NF }
+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
- if (NF != nf_max)
- print "line " NR " has " NF " entries, not " nf_max
}
+
END {
for (i=1; i<=nf_max; i++)
printf(OFMT "%s", sum[i], i < nf_max ? OFS : ORS)
}
+