summaryrefslogtreecommitdiff
path: root/sum1.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 /sum1.awk
parent6bb6be845b6099550e0a530217633e30522093ad (diff)
added shebang, replaced if-elses with shortcut notation, ported online mean and variance calc to mean.awk
Diffstat (limited to 'sum1.awk')
-rw-r--r--sum1.awk13
1 files changed, 6 insertions, 7 deletions
diff --git a/sum1.awk b/sum1.awk
index 02b7d6a..2f5a041 100644
--- a/sum1.awk
+++ b/sum1.awk
@@ -1,3 +1,5 @@
+#!/usr/bin/awk -f
+
### sum1.awk, print column sums
# input: rows of numbers
# output: sum of each column
@@ -6,16 +8,13 @@
{
for (i=1; i<=NF; i++)
sum[i] += $i
- if (NF > maxfld)
- maxfld = NF
+ if (NF > nf_max)
+ nf_max = NF
}
END {
- for (i=1; i<=maxfld; i++) {
+ for (i=1; i<=nf_max; i++) {
printf("%g", sum[i])
- if (i < maxfld)
- printf(" ")
- else
- printf("\n")
+ (i < nf_max) ? printf(" ") : printf("\n")
}
}