mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-22 14:30:29 +00:00
ddb82cb2e0
Maybe someday I'll become adept at using cvs...
26 lines
617 B
Plaintext
26 lines
617 B
Plaintext
# sum3 - print sums of numeric columns
|
|
# input: rows of integers and strings
|
|
# output: sums of numeric columns
|
|
# assumes every line has same layout
|
|
|
|
NR==1 { nfld = NF
|
|
for (i = 1; i <= NF; i++)
|
|
numcol[i] = isnum($i)
|
|
}
|
|
|
|
{ for (i = 1; i <= NF; i++)
|
|
if (numcol[i])
|
|
sum[i] += $i
|
|
}
|
|
|
|
END { for (i = 1; i <= nfld; i++) {
|
|
if (numcol[i])
|
|
printf("%g", sum[i])
|
|
else
|
|
printf("--")
|
|
printf(i < nfld ? "\t" : "\n")
|
|
}
|
|
}
|
|
|
|
function isnum(n) { return n ~ /^[+-]?[0-9]+$/ }
|