diff options
Diffstat (limited to '')
| -rw-r--r-- | sum.awk | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +#!/usr/bin/awk -f
+
+### sum.awk
+# calculate sum of serialized input
+
+
+BEGIN {
+ OFS = FS
+ sign = "[+-]?"
+ decimal = "[0-9]+[.]?[0-9]*"
+ fraction = "[.][0-9]+"
+ exponent = "([Ee]" sign "[0-9]+)?"
+ number = "^" sign "(" decimal "|" fraction ")" exponent "$"
+}
+
+
+NF > 0 {
+ for (n=1; n<=NF; n++) {
+ if ($n ~ number) {
+ count += 1
+ sum += $n
+ }
+ }
+}
+
+
+END {
+ print "sum", "count"
+ print sum, count
+}
+
|
