From 8875b420a873a360a9484778b487394add318a5e Mon Sep 17 00:00:00 2001 From: wukong Date: Wed, 13 Jun 2018 21:41:39 -0700 Subject: added shebang, replaced if-elses with shortcut notation, ported online mean and variance calc to mean.awk --- sum1.awk | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'sum1.awk') 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") } } -- cgit v1.2.3