diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2018-05-27 18:43:20 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2018-05-27 18:43:20 +0300 |
commit | 29f1563294ac1ab19aa252f3fd5fca94c4f88516 (patch) | |
tree | 1acfaad5610df7af96bd9a2ddce1eb3d8b9304e9 /awklib/eg | |
parent | 58cc32a6d4a179b3005f8e4fecbff932da681fba (diff) | |
download | egawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.tar.gz egawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.tar.bz2 egawk-29f1563294ac1ab19aa252f3fd5fca94c4f88516.zip |
Bug fix to extract.awk. Rerun and update files.
Diffstat (limited to 'awklib/eg')
-rw-r--r-- | awklib/eg/network/stoxpred.awk | 29 | ||||
-rw-r--r-- | awklib/eg/prog/extract.awk | 11 | ||||
-rw-r--r-- | awklib/eg/prog/indirectcall.awk | 45 |
3 files changed, 79 insertions, 6 deletions
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) |