summaryrefslogtreecommitdiff
path: root/sum2.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2018-06-13 21:41:39 -0700
committerwukong <wukong@longaeva>2018-06-13 21:41:39 -0700
commit8875b420a873a360a9484778b487394add318a5e (patch)
treed357816354c5d9d4bc3b1db5c43ceda7933b5e3f /sum2.awk
parent6bb6be845b6099550e0a530217633e30522093ad (diff)
added shebang, replaced if-elses with shortcut notation, ported online mean and variance calc to mean.awk
Diffstat (limited to 'sum2.awk')
-rw-r--r--sum2.awk10
1 files changed, 6 insertions, 4 deletions
diff --git a/sum2.awk b/sum2.awk
index 0b2aad3..1df83ae 100644
--- a/sum2.awk
+++ b/sum2.awk
@@ -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")
}