Last Update: 20190611 Local File: "C:\DAN\HTM\GoDaddy\dansher\utut\awk\readme.awk.txt" ==================== Mia culpa! I do confess to being an "awkaholic" - this Mighty Mouse language has me completely hooked. It is hoped you can discover many inspiration(s) from all the AWK/*.awk files herein. The awk syntax is correct (i.e., works), and many useful awk routines can be discovered, cloned, and adapted from them. "AWK/pop_all.awk" is my Opus Magnum to date (03/31/95), having gloriously bettered the capabilities of the Informix (Infamix?) Ace Report Writer. This awk script has several v_e_r_y useful and universally clonable functions: "spc(n)", "col(n)", "unl(n)", "skip(n)", "star(n)", and "yak(blab)". Internal comments explain what they can do for you. /u/spims2/AWK/eq_suk*.awk are interesting exercises in parsing text, and /u/spims2/AWK/wrq_mig.awk is an informative exercise in massaging ASCII data born of SMART/DOS into a record-form acceptable to Informix. All ./*.awk are awk-language command files which are invoked by various /u2/pmet2/SHELLS/*.sh scripts. Here are three invocation-examples from within the squipt /u2/pmet2/SHELLS/pochk.sh awk -F"^" -f $PMS/AWK/poh.awk $f1 >>$TNIRP # Header awk -F"^" -f $PMS/AWK/poi.awk $f2 >>$TNIRP # Items awk -F"^" -f $PMS/AWK/pon.awk $f3 >>$TNIRP # Notes The data which awk will process is contained in "$f1" in the first example. It is a temp file defined as per: f1="/u2/tmp/f1$$" # awk data for PO Header This file is filled by a dbaccess UNLOAD statement within the script, vis: dbaccess $PDB/inpo_pms - << POCH # 2>/dev/null UNLOAD TO "$f1" DELIMITER "^" SELECT pomnum, po_stat, po_blnk, poplant, po_ship, ... POCH In many (most?) cases, it is prudent to SELECT more data for UNLOAD than is actually used by the *.awk command file. Exactly which extra data to grab is best determined by emulating [ab]User-think (distasteful as it is). It will be handy when an [ab]User asks for more/other data on the Report. Below are two example lines from within /u2/pmet2/AWK/poh.awk printf("%5d %10s %-5s %s %s %s %3s %-4s %-21s %-18s\n\n", $1, $11, $10, $2,$3,$19,$4,bla, $8, $9) Actual awk-output from the above command lines look like: 501 08/04/1994 spims V N M law MAIL PGP INDUSTRIES, INC. Charlie Anderson Note that "pomnum", "%5d", and "$1" are but different aspects of the same data entity (sort of a micro-analogy to the Trinity): the Purchase Order Number (501 in the example above). To awk, "$1" represents the first data item, "$2" the second, and so on. It is CRITICALLY IMPORTANT that script UNLOADs are laid out and maintained so that the order of their data columns (e.g., pomnum, po_stat, po_blnk, ...) is always in the precise sequence expected by their corresponding awk command files (*.awk). For this reason, all *.awk should always begin with a reference to their "calling" script(s) and column-map as shown a little bit below. Exampled below are the complete contents of file /u2/pmet2/AWK/poh.awk # poh.awk by Dan Martin (DRM/CTG) Mon Aug 08 13:46:01 CDT 1994 # Called by: SHELLS/pochk.sh - also by its link /u2/pmet2/pochk # SHELLS/ponote.sh - also by its link /u2/pmet2/ponote # SHELLS/pobystat.sh # SHELLS/pobypl.sh # awk fields: # $1 = pomnum, $2 = po_stat, $3 = po_blnk, $4 = poplant, # $5 = po_ship, $6 = podueby, $7 = po_vnd, $8 = v_name, # $9 = po_attn[1,18], $10 = pologad[1,5], $11 = DATE(pocreate), $12 = pomrem, # $13 = poclozon $14 = Ship To $15 = po_rfq, $16 = po_req, # $17 = DATE(poclozon) $18 = Org By $19 = po_fom $20 = faxph, # $21 = acctno, $22 = polastup # main() { if ($19 == "M") bla = "MAIL" else bla = "FAX" printf(" PO # WRITTEN ON AGENT CODES ORG VIA VENDOR NAME ") printf("ATTENTION \n") printf(" ---- ---------- ----- ----- --- ---- --------------------- ") printf("------------------\n") printf("%5d %10s %-5s %s %s %s %3s %-4s %-21s %-18s\n\n", $1, $11, $10, $2,$3,$19,$4,bla, $8, $9) printf("LSTUP %19s V-FAX: %s ACCT: %s\n", $22, $20, $21) printf(" DUE %10s RFQ: %-5d REQ: %-5d SHIP TO: %s\n", $6, $15, $16, $14) printf("CLOSE %10s %s\n", $17, $12) printf(" ======================================") printf("=======================================\n\n") } # EOF poh.awk MISC OTHER USEFUL THINGS ======================== printf(" --------------------------------------") # prints a 77-char printf("---------------------------------------\n") # line of dashes. MISC OTHER MISC =============== The *.bc file(s?) herein contain bc (basic calculator) functions which are used to do math where the integer "precision" of the shell is inadequate (e.g., [ 3.456 -gt 3.455 ] evaluates as false). A bc usage-example from within SHELLS/xfer.sh follows: # opt=`awk -F"^" "{print \\$4}" $v2` # m1=`bc $PMS/AWK/xfer1.bc << DUH # t($ptx,$opt) # quit # DUH` # [ "$m1" -eq "1" ] && phoo 'BUT PT XFER AMOUNT CANNOT EXCEED PT BALANCE.' End of Text