diff options
| author | wukong <wukong@longaeva> | 2018-09-09 23:48:31 -0700 |
|---|---|---|
| committer | wukong <wukong@longaeva> | 2018-09-09 23:48:31 -0700 |
| commit | d1f6c89be163d9399d569e01458242d8ce15e041 (patch) | |
| tree | a263822af5cb1532f9eb1abe7b7ae6334c27d170 /sum4.awk | |
| parent | e42cee748f5bc38d11742739b5e2cad4b6a07c43 (diff) | |
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
Diffstat (limited to 'sum4.awk')
| -rw-r--r-- | sum4.awk | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -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) } } + |
