#!/usr/bin/ksh

CAT=/usr/bin/cat

print "\033[H\033[JImage this is a line from a data file:
       \n\n\n\n\n\nThe rain in Spain falls mainly on the plain!"

read resp

print "\n\n\n"
read resp?"This is how nawk interprets it:"
print "\033[H\033[J\n\n"
$CAT<<'EOF'
+------------------- $0 -------------------+
|                                          |
v                                          v

The rain in Spain falls mainly on the plain!

 ^   ^   ^    ^     ^     ^    ^   ^    ^
 |   |   |    |     |     |    |   |    |
$1  $2  $3   $4    $5    $6   $7  $8   $9

EOF

read resp
read resp?"NAWK is a 'pattern { ACTION }' scripting language:"
print
read resp?" where pattern can be specified as an extended Regular Expression"
print ' such as: /^[Tt]he [a-z]+ in Spain.*!$/'
read resp
read resp?' pattern can also be specified as a condition: $4 == "Spain"'
print "\n\n"
read resp?"Do you think we can specify a pattern and no ACTION?"
print \ such as: /Spain/
read resp
read resp?'The default ACTION is to print the line: { print $0 }'
print ' resulting in: /Spain/ { print $0 }'
read resp
read resp?"Do you think we can specify an { ACTION } only?"
print ' such as: { print $1 }'
read resp
read resp?"{ ACTION } will apply to all lines to the file."

$CAT<<'EOF'


 pattern { ACTION }

 ^                ^
 |                |
 +----- Rule -----+

EOF

read resp
print "\033[H\033[J\c"
read resp?"Here is a complete list of NAWK's built-in variables:"
$CAT<<'EOF'


NF       - Number of fields in current record
RS       - Input record separator  (newline)
FS       - Input field separator  (spaces/tabs)
NR       - Number of records from beginning of first input file
OFS      - Output field separator (space)
ORS      - Output record separator (newline)
FNR      - Number of records from beginning of current file
OFMT     - Output format for numbers (%.6g)
ARGC     - Number of command line arguments
ARGV     - Array of command line arguments
FILENAME - Current input filename
RSTART   - Index into a string, set by match()
RLENGTH  - Length of a substring, set by match()
CONVFMT  - String conversion format for numbers (%.6g)
ENVIRON  - Associative array for environment variables
SUBSEP   - Separator character for array subscripts (\034)
EOF
print
read resp
read resp?"Here is how to find the many implementations of AWK:"
$CAT<<'EOF'

awk/nawk: ls /usr/bin/*awk*
gawk: http://www.gnu.org/software/gawk/gawk.html
GNU Awk User's Guide: http://www.gnu.org/manual/gawk/index.html
Edition 3 of GAWK: Effective AWK Programming: A User's Guide for GNU Awk:
 http://www.gnu.org/manual/gawk-3.1.1/html_mono/gawk.html
tawk: http://www.tasoft.com/tawk.html
mawk (Mike Brennan awk): ftp://ftp.whidbey.net/pub/brennan
mksawk (part of the MKS Toolkit): http://www.mkssoftware.com/
       http://www.mkssoftware.com/docs/man1/awk.1.asp
       http://www.mkssoftware.com/docs/man1/awkc.1.asp
awkcc (an awk compiler to C): http://www.unipress.com/att
awkc++: http://cm.bell-labs.com/cm/cs/who/bwk
awka: http://awka.sourceforge.net
awk2c: ftp://sunsite.unc.edu/pub/Linux/utils/text/awk2c050.tgz
a2p (awk to perl): ls /usr/perl5/bin/a2p
A great awk faq: http://www.faqs.org/faqs/computer-lang/awk/faq
The GAWK pdf reference guide: http://torvalds.cs.mtsu.edu/~neal/awkcard.pdf

EOF

read resp
print "\033[H\033[J\c"
read resp?"Here are the limitations to NAWK/AWK:"
$CAT<<'EOF'
  100 fields
 2500 chars per input record
 2500 chars per output record
 1024 chars per field
 1024 chars per printf string
  400 chars max literal string
  400 chars in char class
   15 open files
    1 pipe
 double-precision floating point
EOF

read resp
print "\n\nHappy Nawk scripting!\n\nWarning:
       \ntoo much NAWKing might make you into a NAWKaholic!"
