summaryrefslogtreecommitdiff
path: root/sum3.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 /sum3.awk
parent6bb6be845b6099550e0a530217633e30522093ad (diff)
added shebang, replaced if-elses with shortcut notation, ported online mean and variance calc to mean.awk
Diffstat (limited to '')
-rw-r--r--sum3.awk17
1 files changed, 9 insertions, 8 deletions
diff --git a/sum3.awk b/sum3.awk
index b4100a7..8ceda8b 100644
--- a/sum3.awk
+++ b/sum3.awk
@@ -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]+$/
-}
-