From d1f6c89be163d9399d569e01458242d8ce15e041 Mon Sep 17 00:00:00 2001 From: wukong Date: Sun, 9 Sep 2018 23:48:31 -0700 Subject: added summations to quad_reg added in-progress lpf.awk (low pass filter), an adaptation of convolution script (conv.awk) to use delmitied columns as input additional tweaking of OFMT, OFS, and conditional print statements --- sum4.awk | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'sum4.awk') diff --git a/sum4.awk b/sum4.awk index 6a06455..aa3f044 100644 --- a/sum4.awk +++ b/sum4.awk @@ -4,6 +4,7 @@ # input: rows of integers and strings # output: sums of numeric columns + function isnum(n) { sign = "[+-]?" decimal = "[0-9]+[.]?[0-9]*" @@ -13,24 +14,33 @@ function isnum(n) { return n ~ number } -NR==1 { + +BEGIN { OFS = FS } + +NR == 1 { nf_max = NF - for (i=1; i<=NF; i++) { - (!isnum($i)) ? header[i] = $i : header[i] = "col" i - } + for (i=1; i<=NF; i++) + isnum($i) ? header[i] = "col" i : header[i] = $i } { + if (NF > nf_max) + nf_max = NF for (i=1; i<=NF; i++) { - sum[i] += $i - count[i]++ + if ($i == header[i]) + continue + if (isnum($i)) { + count[i]++ + sum[i] += $i + } } } END { for (i=1; i<=nf_max; i++) { - if (header[i]) - printf("%s:" OFS, header[i]) - printf(OFMT ORS, sum[i]) + printf((header[i]) ? header[i] OFS : OFS) + printf((count[i]) ? count[i] OFS sum[i] : OFS) + printf(ORS) } } + -- cgit v1.2.3