aboutsummaryrefslogtreecommitdiffstats
path: root/awklib
diff options
context:
space:
mode:
Diffstat (limited to 'awklib')
-rw-r--r--awklib/ChangeLog4
-rw-r--r--awklib/eg/network/stoxpred.awk29
-rw-r--r--awklib/eg/prog/extract.awk11
-rw-r--r--awklib/eg/prog/indirectcall.awk45
-rw-r--r--awklib/extract.awk10
5 files changed, 88 insertions, 11 deletions
diff --git a/awklib/ChangeLog b/awklib/ChangeLog
index 4fdcb8b2..acc0d205 100644
--- a/awklib/ChangeLog
+++ b/awklib/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * extract.awk: Updated after changes.
+
2018-04-11 Arnold D. Robbins <arnold@skeeve.com>
* .gitignore: Add pwcat.c and grcat.c. Remove igawk. Sort the list.
diff --git a/awklib/eg/network/stoxpred.awk b/awklib/eg/network/stoxpred.awk
index 62744c14..aa1fbe9f 100644
--- a/awklib/eg/network/stoxpred.awk
+++ b/awklib/eg/network/stoxpred.awk
@@ -1,3 +1,32 @@
+BEGIN {
+ Init()
+ ReadQuotes()
+ CleanUp()
+ Prediction()
+ Report()
+ SendMail()
+}
+function Init() {
+ if (ARGC != 1) {
+ print "STOXPRED - daily stock share prediction"
+ print "IN:\n no parameters, nothing on stdin"
+ print "PARAM:\n -v Proxy=MyProxy -v ProxyPort=80"
+ print "OUT:\n commented predictions as email"
+ print "JK 09.10.2000"
+ exit
+ }
+ # Remember ticker symbols from Dow Jones Industrial Index
+ StockCount = split("AA GE JNJ MSFT AXP GM JPM PG BA HD KO \
+ SBC C HON MCD T CAT HWP MMM UTX DD IBM MO WMT DIS INTC \
+ MRK XOM EK IP", name);
+ # Remember the current date as the end of the time series
+ day = strftime("%d")
+ month = strftime("%m")
+ year = strftime("%Y")
+ if (Proxy == "") Proxy = "chart.yahoo.com"
+ if (ProxyPort == 0) ProxyPort = 80
+ YahooData = "/inet/tcp/0/" Proxy "/" ProxyPort
+}
function ReadQuotes() {
# Retrieve historical data for each ticker symbol
FS = ","
diff --git a/awklib/eg/prog/extract.awk b/awklib/eg/prog/extract.awk
index f5dfcf40..ff598e8e 100644
--- a/awklib/eg/prog/extract.awk
+++ b/awklib/eg/prog/extract.awk
@@ -30,7 +30,7 @@ BEGIN { IGNORECASE = 1 }
}
if ($3 != curfile) {
if (curfile != "")
- close(curfile)
+ filelist[curfile]++ # save to close later
curfile = $3
}
@@ -60,14 +60,13 @@ BEGIN { IGNORECASE = 1 }
print join(a, 1, n, SUBSEP) > curfile
}
}
+END {
+ for (f in filelist)
+ close(filelist[f])
+}
function unexpected_eof()
{
printf("extract: %s:%d: unexpected EOF or error\n",
FILENAME, FNR) > "/dev/stderr"
exit 1
}
-
-END {
- if (curfile)
- close(curfile)
-}
diff --git a/awklib/eg/prog/indirectcall.awk b/awklib/eg/prog/indirectcall.awk
index 165b022a..b2b82686 100644
--- a/awklib/eg/prog/indirectcall.awk
+++ b/awklib/eg/prog/indirectcall.awk
@@ -1,3 +1,48 @@
+# indirectcall.awk --- Demonstrate indirect function calls
+#
+# Arnold Robbins, arnold@skeeve.com, Public Domain
+# January 2009
+# average --- return the average of the values in fields $first - $last
+
+function average(first, last, sum, i)
+{
+ sum = 0;
+ for (i = first; i <= last; i++)
+ sum += $i
+
+ return sum / (last - first + 1)
+}
+
+# sum --- return the sum of the values in fields $first - $last
+
+function sum(first, last, ret, i)
+{
+ ret = 0;
+ for (i = first; i <= last; i++)
+ ret += $i
+
+ return ret
+}
+# For each record, print the class name and the requested statistics
+{
+ class_name = $1
+ gsub(/_/, " ", class_name) # Replace _ with spaces
+
+ # find start
+ for (i = 1; i <= NF; i++) {
+ if ($i == "data:") {
+ start = i + 1
+ break
+ }
+ }
+
+ printf("%s:\n", class_name)
+ for (i = 2; $i != "data:"; i++) {
+ the_function = $i
+ printf("\t%s: <%s>\n", $i, @the_function(start, NF) "")
+ }
+ print ""
+}
# num_lt --- do a numeric less than comparison
function num_lt(left, right)
diff --git a/awklib/extract.awk b/awklib/extract.awk
index 2662574b..96fc9498 100644
--- a/awklib/extract.awk
+++ b/awklib/extract.awk
@@ -30,7 +30,7 @@ BEGIN { IGNORECASE = 1 }
}
if ($3 != curfile) {
if (curfile != "")
- close(curfile)
+ filelist[curfile]++ # save to close later
curfile = $3
}
@@ -60,6 +60,10 @@ BEGIN { IGNORECASE = 1 }
print join(a, 1, n, SUBSEP) > curfile
}
}
+END {
+ for (f in filelist)
+ close(filelist[f])
+}
function unexpected_eof()
{
printf("extract: %s:%d: unexpected EOF or error\n",
@@ -67,10 +71,6 @@ function unexpected_eof()
exit 1
}
-END {
- if (curfile)
- close(curfile)
-}
# join.awk --- join an array into a string
#
# Arnold Robbins, arnold@gnu.org, Public Domain