home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gawk-2.15.5-src.lha / GNU / src / amiga / gawk-2.15.5 / vms / gawk.hlp < prev    next >
Encoding:
Text File  |  1992-07-06  |  59.6 KB  |  1,190 lines

  1. ! Gawk.Hlp
  2. !                                                       Pat Rankin, Jun'90
  3. !                                                          revised, Jun'91
  4. !                                                          revised, Jul'92
  5. !   Online help for GAWK.
  6. !
  7. 1 GAWK
  8.  GAWK is GNU awk, the Free Software Foundation's implementation of
  9.  the awk programming language.  awk is an interpretive language which
  10.  can handle many data-reformatting jobs with just a few lines of code.
  11.  It has powerful string manipulation and pattern matching capabilities
  12.  built in.  This version should be compatible with POSIX 1003.2 awk.
  13.  
  14.  The VMS version of GAWK supports both the original UN*X-style command
  15.  interface and a DCL interface.  The only setup requirement for GAWK
  16.  is to define it as a 'foreign' command:  a DCL symbol with a value
  17.  which begins with '$'.
  18.        $ GAWK :== $disk:[directory]GAWK
  19. 2 GNU_syntax
  20.  GAWK's UN*X-style interface uses the 'dash' convention for specifying
  21.  options and uses spaces to separate multiple arguments.
  22.  
  23.  There are two main alternatives, depending on how the awk program is
  24.  to be passed to GAWK.  Both alternatives share most options.
  25.  
  26.  Usage: $ gawk [-W opts] [-F fs] [-v var=val] -f progfile [--] file ...
  27.     or  $ gawk [-W opts] [-F fs] [-v var=val] [--] "program" file ...
  28.  
  29.  The options are case-sensitive.  On VMS, the DCL command interpreter
  30.  converts unquoted text into uppercase before passing it to the running
  31.  program.  However, GAWK is written in 'C' and the C Run-Time Library
  32.  (VAXCRTL) converts unquoted text into *lowercase*.  Therefore, the
  33.  -Fval and -W options must be enclosed in quotes.
  34.  
  35.  Note:  under VMS POSIX, the usual shell command line processing occurs.
  36. 3 options
  37.  -f file    use the specified file as the awk program source; if more
  38.             than one instance of -f is used, each file will be read
  39.             in succession
  40.  -Fstring   define a value for the FS variable (field separator)
  41.  -v var=val assign a value of 'val' to the variable 'var'
  42.  -W 'options'  additional gawk-specific options; multiple values may
  43.             be separated by commas, or by spaces if they're quoted,
  44.             or mulitple occurrences of -W may be used.
  45.  -W compat  use awk "compatibility mode" to disable GAWK extensions
  46.             and get the behavior of UN*X awk.
  47.  -W copyright [or -W copyleft]  display an abbreviated version of
  48.             the GNU copyright information
  49.  -W lint    warn about suspect or non-portable awk program code
  50.  -W posix   compatibility mode with additional restrictions
  51.  -W version display program version number
  52.  --         don't check further arguments for leading dash
  53. 3 program_text
  54.  If the '-f file' option is not used on the command line, then the
  55.  first "non-dash" argument is assumed to be a string of text containing
  56.  the awk source program.  Here is a complete sample program:
  57.        $ gawk -- "BEGIN {print ""\nHello, World!\n""}"
  58.  This program would print a blank line (based on first "\n"), followed
  59.  by a line reading "Hello, World!", followed by another blank line
  60.  (since awk's 'print' statement includes the trailing 'newline').
  61.  
  62.  On VMS, to include a quote character inside of a quoted string, two
  63.  successive quotes ("") must be used.  (Not necessary for VMS POSIX.)
  64. 3 data_files
  65.  After all dash-options are examined, and after the program text if
  66.  there were no occurrences of the -f option, remaining (space separated)
  67.  command line arguments are considered to be data files for the awk
  68.  program to process.  If any of these actually contains an equals sign
  69.  (=), then it is interpreted as a variable assignment instead of a data
  70.  file.  The syntax is 'variable_name=value'.  For example, the command
  71.        $ gawk -f myprog.awk infile.one flag=2 start=0 infile.two
  72.  would read file 'infile.one' for the program in 'myprog.awk', then it
  73.  would set 'flag' to 2 and 'start' to 0, and finally it would read file
  74.  'infile.two' for the program.  Note that in a case like this, the two
  75.  assignments actually occur after the first file has been processed,
  76.  not at program startup when the command line is first scanned.
  77. 3 IO_redirection
  78.  The command parsing in the VMS implementation of GAWK does some
  79.  emulation of a UN*X-style shell, where certain characters on the
  80.  command line have special meaning.  In particular, the symbols '<',
  81.  '>', '|', '*', and '?' receive special handling before the main part
  82.  of the program has a chance to see them.  The symbols '<' and '>'
  83.  perform some file manipulation from the command line:
  84.  
  85.  <ifile     open file 'ifile' (readonly) as 'stdin' [SYS$INPUT]
  86.  >nfile     create 'nfile' as 'stdout' [SYS$OUTPUT], in stream-lf format
  87.  >>ofile    append to 'ofile' for 'stdout'; create it if necessary
  88.  >&efile    point 'stderr' [SYS$ERROR] at 'efile', but don't open it yet
  89.  >$vfile    create 'vfile' as 'stdout', using RMS attributes appropriate
  90.             for a standard text file (variable length records with
  91.             implied carriage control)
  92.  2>&1       route error messages into the regular output stream
  93.  1>&2       send output data to the error destination
  94.  <<sentinel error; reading stdin until 'sentinel' not supported
  95.  <-, >-     error; closure of stdin or stdout from cmd line not supported
  96.  >>$vfile   incorrect; would be interpreted as file "$vfile" in stream-lf
  97.             format rather than as file "vfile" in RMS 'text' format
  98.  |          error; command line pipes not supported
  99.  
  100.  Note:  under VMS POSIX these features are implemented by the shell
  101.  rather than inside GAWK, so consult the shell documentation for
  102.  specific details.
  103. 3 wildcard_expansion
  104.  The command parsing in the VMS implementation of GAWK does some
  105.  emulation of a UN*X-style shell, where certain characters on the
  106.  command line have special meaning.  In particular, the symbols '<',
  107.  '>', '*', '%', and '?' receive special handling before the main part
  108.  of the program has a chance to see them.  The symbols '*', '%' and '?'
  109.  are used as wildcards in filenames.  '*' and '%' have their usual VMS
  110.  meanings of multiple character and single character wildcards,
  111.  respectively, and '?' is also treated as a single character wildcard.
  112.  
  113.  When a command line argument that should be a filename contains any
  114.  of the wildcard characters, a directory lookup is attempted for files
  115.  which match the specified pattern.  If one or more matching files are
  116.  found, those filenames are put into the command line in place of the
  117.  original pattern.  If no matching files are found, the original
  118.  pattern is left in place.
  119.  
  120.  Note:  under VMS POSIX wildcard expansion, or "file globbing", is
  121.  performed by the shell rather than inside GAWK, so consult the shell
  122.  documentation for details.  In particular, the last sentence of the
  123.  previous paragraph does not apply.
  124. 2 DCL_syntax
  125.  GAWK's DCL-style interface is more or less a standard DCL command, with
  126.  one required parameter.  Multiple values--when present--are separated
  127.  by commas.
  128.  
  129.  There are two main alternatives, depending on how the awk program is
  130.  to be passed to GAWK.  Both alternatives share most options.
  131.  
  132.  Usage:  GAWK  /COMMANDS="awk program text"  data_file[,data_file,...]
  133.     or   GAWK  /INPUT=awk_file  data_file[,"Var=value",data_file,...]
  134.  (  or   GAWK  /INPUT=(awk_file1,awk_file2,...)  data_file[,...]       )
  135.  
  136.  Not applicable under VMS POSIX.
  137. 3 Parameter
  138.  data_file[,datafile,...]       (data_file data_file ...)
  139.  data_file[,"Var=value",...,data_file,...]      (data_file Var=value &c)
  140.  
  141.   Data file(s) for the awk program to process.  If any of these
  142.   actually contains an equals sign (=), then it is interpreted as
  143.   a variable assignment instead of a data file.  The syntax is
  144.   "variable_name=value".  Quotes are required for non-file parameters.
  145.  
  146.   For example, the command
  147.        $ gawk/input=myprog.awk infile.one,"flag=2","start=0",infile.two
  148.   would read file 'infile.one' for the program in 'myprog.awk', then it
  149.   would set 'flag' to 2 and 'start' to 0, and finally it would read file
  150.   'infile.two' for the program.  Note that in a case like this, the two
  151.   assignments actually occur after the first file has been processed,
  152.   not at program startup when the command line is first scanned.
  153.  
  154.   Wildcard file lookups are attempted on data file specifications.  See
  155.   subtopic 'GAWK GNU_syntax wildcard_expansion' for details.
  156.  
  157.   At least one data_file parameter value is required.  An exception is
  158.   made if /usage, /version, or /copyright is specified *and* if GAWK is
  159.   defined as a 'foreign' command rather than a 'native' DCL command.
  160. 3 Qualifiers
  161. /COMMANDS
  162.  /COMMANDS="awk program text"   (-- "awk program text")
  163.  
  164.   For short programs, it is possible to include the complete program
  165.   on the command line.  The quotes are required.  Here is a complete
  166.   sample program:
  167.        $ gawk/commands="BEGIN {print ""\nHello, World!\n""}" NL:
  168.   This program would print a blank line (based on first "\n"), followed
  169.   by a line reading "Hello, World!", followed by another blank line
  170.   (since awk's 'print' statement includes the trailing 'newline').
  171.  
  172.   To include a quote character inside of a quoted string, two
  173.   successive quotes ("") must be used.
  174.  
  175.   Either /COMMANDS or /INPUT (but not both) must be supplied.
  176. /INPUT
  177.  /INPUT=(awk_file1,awk_file2)   (-f awk_file1 -f awk_file2)
  178.  
  179.   Used to specify one or more files containing the source code of
  180.   the awk program.  If more than one file is used, separate them
  181.   with commas and enclose the list in parentheses.
  182.  
  183.   Multiple source files are processed in order as if they had been
  184.   concatenated together.
  185.  
  186.   Either /INPUT or /COMMANDS (but not both) must be supplied.
  187. /FIELD_SEPARATOR
  188.  /FIELD_SEPARATOR="FS_value"    (-F"FS_value")
  189.  
  190.   Assign a value to the built in variable FS (field separator).
  191. /VARIABLES
  192.  /VARIABLES=("Var1=val1","Var2=val2",...)  (-v Var1=val1 -v Var2=val2)
  193.  
  194.   Assign value(s) to the specified variable(s).
  195. /REG_EXPR
  196.  /REG_EXPR={AWK | EGREP | POSIX}   (-a vs -e options [obsolete])
  197.  
  198.   This qualifier is obsolete and has no effect.
  199. /STRICT
  200.  /[NO]STRICT            (-"W compat" option)
  201.  
  202.   Use strict awk compatibility mode (/strict) and suppress GAWK
  203.   extensions.  The default is /NOSTRICT.
  204. /POSIX
  205.  /[NO]POSIX             (-"W posix" option)
  206.  
  207.   Use POSIX compatibility mode (/posix) and suppress GAWK extensions.
  208.   The default is /NOPOSIX.  Slightly more restrictive than /strict.
  209. /LINT
  210.  /[NO]LINT              (-"W lint" option)
  211.  
  212.   Check the awk program cafefully for potential problems that might
  213.   be encountered if it were to be used with other awk implementations,
  214.   and print warnings for anything found.  The default in /NOLINT.
  215. /VERSION
  216.  /VERSION               (-"W version" option)
  217.  
  218.   Print GAWK's version number.
  219. /COPYRIGHT
  220.  /COPYRIGHT             (-"W copyright" or -"W copyleft" option)
  221.  
  222.   Print a brief version of GAWK's copyright notice.
  223. /USAGE
  224.  /USAGE                 (no corresponding GNU_syntax option)
  225.  
  226.   Print a compact summary of the command line options.
  227.  
  228.   After the 'usage' message is printed, GAWK terminates regardless
  229.   of any other command line options.
  230. /OUTPUT
  231.  /OUTPUT=out_file       (>$out_file)
  232.  
  233.   Write program output into 'out_file'.  The default is SYS$OUTPUT.
  234. 2 awk_language
  235.  An awk program consists of one or more pattern-action pairs, sometimes
  236.  referred to as "rules".  For each record of an input (data) file, the
  237.  rules are checked sequentially.  Any pattern which matches the input
  238.  record triggers that rule's action.  Actions are instructions which
  239.  resemble statements in the 'C' programming language.  Patterns come
  240.  in several varieties, including field comparisons, regular expression
  241.  matching, and special cases defined by reserved keywords.
  242.  
  243.  All awk keywords and variables are case-sensitive.  Text matching is
  244.  also sensitive to character case unless the builtin variable IGNORECASE
  245.  is set to a non-zero value.
  246. 3 rules
  247.  The syntax for a pattern-action 'rule' is simply
  248.        PATTERN { ACTION }
  249.  where the braces ({}) are required punctuation for the action.
  250.  Semicolons (;) or 'newlines' (ie, having the text on a separate line)
  251.  delimit multiple rules and also multiple actions within a given rule.
  252.  Either the pattern or the action may be omitted; an empty pattern
  253.  matches every record of the input file; a missing action (not an empty
  254.  action inside of braces), is an implicit request to print the current
  255.  record; an empty action (ie, {}) is legal but not very useful.
  256. 3 patterns
  257.  There are several types of patterns available for awk rules.
  258.  
  259.   expression  an 'expression' is something to be evaluated (perhaps
  260.                          a comparison or function call) which will
  261.                          be considered true if non-zero (for numeric
  262.                          results) or if non-null (for strings)
  263.   /regular_expression/ slashes (/) delimit a regular expression
  264.                          which is used as a pattern
  265.   pattern1, pattern2   a pair of patterns separated by a comma (,),
  266.                          which causes a range of records to trigger
  267.                          the associated action; the records which
  268.                          match the patterns are included in the range
  269.   <null>      an omitted pattern (in this text, the  string '<null>'
  270.                          is displayed, but in an awk program, it
  271.                          would really be blank) matches every record
  272.   BEGIN       keyword for specifying a rule to be executed prior to
  273.                          reading the 1st record of the 1st input file
  274.   END         keyword for specifying a rule to be executed after
  275.                          handling the last input record of last file
  276. 4 examples
  277.  Some example patterns (mostly with the corresponding actions omitted)
  278.  
  279.  NF > 0     # comparison expression:  matches non-null records
  280.  $0         # implied comparison:  also matches non-null records
  281.  $2 > 1000 && sum <= 999999     # slightly more elaborate expression
  282.  /x/        # regular expression matching any record with an 'x' in it
  283.  /^ /       # reg-expr matching records beginning with a space
  284.  $1 == "start", $NF == "stop"   # range pattern for input in which
  285.                 some data lines begin with 'start' and/or end with
  286.                 'stop' in order to collect groups of records
  287.         { sum += $1 }   # null pattern:  it's action (add field #1 to
  288.                 variable 'sum') would be executed for every record
  289.  BEGIN  { sum = 0 }     # keyword 'BEGIN':  perform this action before
  290.                 reading the input file (note: initialization to 0 is
  291.                 unnecessary in awk)
  292.  END    { print "total =", sum }    # keyword 'END':  perform this
  293.                 action after the last input record has been processed
  294. 3 actions
  295.  An 'action' is something to do when a given record has matched the
  296.  corresponding pattern in a rule.  In general, actions resemble 'C'
  297.  statements and expressions.  The action in a rule must be enclosed
  298.  in braces ({}).
  299.  
  300.  Each action can contain more than one statement or expression to be
  301.  executed, provided that they're separated by semicolons (;) and/or
  302.  on separate lines.
  303.  
  304.  An omitted action is equivalent to
  305.        { print $0 }
  306.  which prints the current record.
  307. 3 operators
  308.  Relational operators
  309.     ==    compare for equality
  310.     !=    compare for inequality
  311.     <, <=, >, >=  numerical or lexical comparison (less than, less or
  312.                     equal, greater than, greater or equal, respectively)
  313.     ~     match against a regular expression
  314.     !~    match against a regular expression, but accept failed matches
  315.             instead of successful ones
  316.  Arithmetic operators
  317.     +     addition
  318.     -     subtraction
  319.     *     multiplication
  320.     /     division
  321.     %     remainder
  322.     ^, ** exponentiation ('**' is a synonym for '^', unless POSIX
  323.             compatibility is specified, in which case it's invalid)
  324.  Boolean operators (aka Logical operators)
  325.           a value is considered false if it's 0 or a null string,
  326.             it is true otherwise; the result of a boolean operation
  327.             (and also of a comparison operation) will be 0 when false
  328.             or 1 when true
  329.     ||    or [expression (a || b) is true if either a is true or b
  330.             is true or both a and b are true; it is false otherwise;
  331.             b is not evaluated unless a is false (ie, short-circuit)]
  332.     &&    and [expression (a && b) is true if both a and b are true;
  333.             it is false otherwise; b is only evaluated if a is true]
  334.     !     not [expression (!a) is true if a is false, false otherwise]
  335.     in    array membership; the keyword 'in' tests whether the value
  336.             on the left represents a current subscript in the array
  337.             named on the right
  338.  Conditional operator
  339.     ? :   the conditional operator takes three operands; the first is
  340.             an expression to evaluate, the second is the expression to
  341.             use if the first was true, the third is the expression to
  342.             use if it was false [simple example (a < b ? b : a) gives
  343.             the maximum of a and b]
  344.  Assignment operators
  345.     =     store the value on the right into the variable or array slot
  346.             on the left [expression (a = b) stores the value of b in a]
  347.     +=, -=, *=, /=, %=, ^=, **=  perform the indicated arithmetic
  348.            operation using the current value of the variable or array
  349.             element of the left side and the expression on the right
  350.             side, then store the result in the left side
  351.     ++    increment by 1 [expression (++a) gets the current value of
  352.             a and adds 1 to it, stores that back in a, and returns the
  353.             new value; expression (a++) gets the current value of a,
  354.             adds 1 to it, stores that back in a, but returns the
  355.             original value of a]
  356.     --    decrement by 1 (analogous to increment)
  357.  String operators
  358.           there is no explicit operator for string concatenation;
  359.             two values and/or variables side-by-side are implicitly
  360.             concatenated into a string (numeric values are first
  361.             converted into their string equivalents)
  362.  Conversion between numeric and string values
  363.           there is no explicit operator for conversion; adding 0
  364.             to a string with force it to be converted to a number
  365.             (the numeric value will be 0 if the string does not
  366.             represent an integer or floating point number); the
  367.             reverse, converting a number into a string, is done by
  368.             concatenating a null string ("") to it [the expression
  369.             (5.75 "") evaluates to "5.75"]
  370.  Field 'operator'
  371.     $     prefixing a number or variable with a dollar sign ($)
  372.             causes the appropriate record field to be returned [($2)
  373.             gives the second field of the record, ($NF) gives the
  374.             last field (since the builtin variable NF is set to the
  375.             number of fields in the current record)]
  376.  Array subscript operator
  377.     ,     multi-dimensional arrays are simulated by using comma (,)
  378.             separated array indices; the actual index is generated
  379.             by replacing commas with the value of builtin SUBSEP,
  380.             then concatenating the expression into a string index
  381.           [comma is also used to separate arguments in function
  382.             calls and user-defined function definitions]
  383.           [comma is *also* used to indicate a range pattern in an
  384.             awk rule]
  385.  Escape 'operator'
  386.     \     In quoted character strings, the backslash (\) character
  387.             causes the following character to be interpreted in a
  388.             special manner [string "one\ntwo" has an embedded newline
  389.             character (linefeed on VMS, but treated as if it were both
  390.             carriage-return and linefeed); string "\033[" has an ASCII
  391.             'escape' character (which has octal value 033) followed by
  392.             a 'right-bracket' character]
  393.           Backslash is also used in regular expressions
  394.  Redirection operators
  395.     <     Read-from -- valid with 'getline'
  396.     >     Write-to (create new file) -- valid with 'print' and 'printf'
  397.     >>    Append-to (create file if it doesn't already exist)
  398.     |     Pipe-from/to -- valid with 'getline', 'print', and 'printf'
  399. 4 precedence
  400.  Operator precedence, listed from highest to lowest.  Assignment,
  401.  conditional, and exponentiation operators group from right to left;
  402.  all others group from left to right.  Parentheses may be used to
  403.  override the normal order.
  404.  
  405.      field ($)
  406.      increment (++), decrement (--)
  407.      exponentiation (^, **)
  408.      unary plus (+), unary minus (-), boolean not (!)
  409.      multiplication (*), division (/), remainder (%)
  410.      addition (+), subtraction (-)
  411.      concatenation (no special symbol; implied by context)
  412.      relational (==, !=, <, >=, etc), and redirection (<, >, >>, |)
  413.        Relational and redirection operators have the same precedence
  414.        and use similar symbols; context distinguishes between them
  415.      matching (~, !~)
  416.      array membership ('in')
  417.      boolean and (&&)
  418.      boolean or (||)
  419.      conditional (? :)
  420.      assignment (=, +=, etc)
  421. 4 escaped_characters
  422.  Inside of a quoted string or constant regular expression, the
  423.  backslash (\) character gives special meaning to the character(s)
  424.  after it.  Special character letters are case sensitive.
  425.     \\    results in one backslash in the string
  426.     \a    is an 'alert' (<ctrl/G>. the ASCII <bell> character)
  427.     \b    is a backspace (BS, <ctrl/H>)
  428.     \f    is a form feed (FF, <ctrl/L>)
  429.     \n    'newline' (<ctrl/J> [line feed treated as CR+LF]
  430.     \r    carriage return (CR, <ctrl/M> [re-positions at the
  431.             beginning of the current line]
  432.     \t    tab (HT, <ctrl/I>)
  433.     \v    vertical tab (VT, <ctrl/K>)
  434.     \###  is an arbitrary character, where '###' represents 1 to 3
  435.             octal (ie, 0 thru 7) digits
  436.     \x##  is an alternate arbitrary character, where '##' represents
  437.             1 or more hexadecimal (ie, 0 thru 9 and/or A through E
  438.             and/or a through e) digits; if more than two digits
  439.             follow, the result is undefined; not recognized if POSIX
  440.             compatibility mode is specified.
  441. 3 statements
  442.  A statement refers to a unit of instruction found in the action
  443.  part of an awk rule, and also found in the definition of a function.
  444.  The distinction between action, statement, and expression usually
  445.  won't matter to an awk programmer.
  446.  
  447.  Compound statements consist of multiple statements separated by
  448.  semicolons or newlines and enclosed within braces ({}).  They are
  449.  sometimes referred to as 'blocks'.
  450. 4 expressions
  451.  An expression such as 'a = 10' or 'n += i++' is a valid statement.
  452.  
  453.  Function invocations such as 'reformat_field($3)' are also valid
  454.  statements.
  455. 4 if-then-else
  456.  A conditional statement in awk uses the same syntax as for the 'C'
  457.  programming language:  the 'if' keyword, followed by an expression
  458.  in parentheses, followed by a statement--or block of statements
  459.  enclosed within braces ({})--which will be executed if the expression
  460.  is true but skipped if it's false.  This can optionally be followed
  461.  by the 'else' keyword and another statement--or block of statements--
  462.  which will be executed if (and only if) the expression was false.
  463. 5 examples
  464.  Simple example showing a statement used to control how many numbers
  465.  are printed on a given line.
  466.        if ( ++i <= 10 )     #check whether this would be the 11th
  467.               printf(" %5d", k)     #print on current line if not
  468.        else {
  469.               printf("\n %5d", k)   #print on next line if so
  470.               i = 1                 #and reset the counter
  471.        }
  472.  Another example ('next' is described under 'action-controls')
  473.        if ($1 > $2) { print "rejected"; next } else diff = $2 - $1
  474. 4 loops
  475.  Three types of loop statements are available in awk.  Each uses
  476.  the same syntax as 'C'.  The simplest of the three is the 'while'
  477.  statement.  It consists of the 'while' keyword, followed by an
  478.  expression enclosed within parentheses, followed by a statement--or
  479.  block of statements in braces ({})--which will be executed if the
  480.  expression evaluates to true.  The expression is evaluated before
  481.  attempting to execute the statement; if it's true, the statement is
  482.  executed (the entire block of statements if there is a block) and
  483.  then the expression is re-evaluated.
  484.  
  485.  The second type of loop is the do-while loop.  It consists of the
  486.  'do' keyword, followed by a statement (usually a block of statements
  487.  enclosed within braces), followed by the 'while' keyword, followed
  488.  by a test expression enclosed within parentheses.  The statement--or
  489.  block--is always executed at least once.  Then the test expression
  490.  is evaluated, and the statement(s) re-executed if the result was
  491.  true (followed by re-evaluation of the test, and so on).
  492.  
  493.  The most complex of the three loops is the 'for' statement, and it
  494.  has a second variant that is not found in 'C'.  The ordinary for-loop
  495.  consists of the 'for' keyword, followed by three semicolon-separated
  496.  expressions enclosed within parentheses, followed by a statement or
  497.  brace-enclosed block of statements.  The first of the three
  498.  expressions is an initialization clause; it is done before starting
  499.  the loop.  The second expression is used as a test, just like the
  500.  expression in a while-loop.  It is checked before attempting to
  501.  execute the statement block, and then re-checked after each execution
  502.  (if any) of the block.  The third expression is an 'increment' clause;
  503.  it is evaluated after an execution of the statement block and before
  504.  re-evaluation of the test (2nd) expression.  Normally, the increment
  505.  clause will change a variable used in the test clause, in such a
  506.  fashion that the test clause will eventually evaluate to false and
  507.  cause the loop to finish.
  508.  
  509.  Note to 'C' programmers:  the comma (,) operator commonly used in
  510.  'C' for-loop expressions is not valid in awk.
  511.  
  512.  The awk-specific variant of the for-loop is used for processing
  513.  arrays.  Its syntax is 'for' keyword, followed by variable_name 'in'
  514.  array_name (where 'var in array' is enclosed in parentheses),
  515.  followed by a statement (or block).  Each valid subscript value for
  516.  the array in question is successively placed--in no particular
  517.  order--into the specified 'index' variable.
  518. 5 while_example
  519.  # strip fields from the input record until there's nothing left
  520.  while (NF > 0) {
  521.      $1 = ""    #this will affect the value of $0
  522.      $0 = $0    #this causes $0 and NF to be re-evaluated
  523.      print
  524.  }
  525. 5 do_while_example
  526.  # This is a variation of the while_example; it gives a slightly
  527.  #   different display due to the order of operation.
  528.  # echo input record until all fields have been stripped
  529.  do {
  530.      print      #output $0
  531.      $1 = ""    #this will affect the value of $0
  532.      $0 = $0    #this causes $0 and NF to be re-evaluated
  533.  } while (NF > 0)
  534. 5 for_example
  535.  # echo command line arguments (won't include option switches)
  536.  for ( i = 0; i < ARGC; i++ )  print ARGV[i]
  537.  
  538.  # display contents of builtin environment array
  539.  for (itm in ENVIRON)
  540.      print itm, ENVIRON[itm]
  541. 4 loop-controls
  542.  There are two special statements--both from 'C'--for changing the
  543.  behavior of loop execution.  The 'continue' statement is useful in
  544.  a compound (block) statement; when executed, it effectively skips
  545.  the rest of the block so that the increment-expression (only for
  546.  for-loops) and loop-termination expression can be re-evaluated.
  547.  
  548.  The 'break' statement, when executed, effectively skips the rest
  549.  of the block and also treats the test expression as if it were
  550.  false (instead of actually re-evaluating it).  In this case, the
  551.  increment-expression of a for-loop is also skipped.
  552.  
  553.  'break' is only allowed within a loop ('for', 'while', or
  554.  'do-while').  If 'continue' is used outside of a loop, it is
  555.  treated like 'next' (see action-controls).  Inside nested loops,
  556.  both 'break' and 'continue' only apply to the innermost loop.
  557. 4 action-controls
  558.  There are two special statements for controlling statement execution.
  559.  The 'next' statement, when executed, causes the rest of the current
  560.  action and all further pattern-action rules to be skipped, so that
  561.  the next input record will be immediately processed.  This is useful
  562.  if any early action knows that the current record will fail all the
  563.  remaining patterns; skipping those rules will reduce processing time.
  564.  An extended form, 'next file', is also available.  It causes the
  565.  remainder of the current file to be skipped, and then either the
  566.  next input file will be processed, if any, or the END action will be
  567.  performed.  'next file' is not available in traditional awk.
  568.  
  569.  The 'exit' statement causes GAWK execution to terminate.  All open
  570.  files are closed, and no further processing is done.  The END rule,
  571.  if any, is executed.  'exit' takes an optional numeric value as a
  572.  argument which is used as an exit status value, so that some sort
  573.  of indication of why execution has stopped can be passed on to the
  574.  user's environment.
  575. 4 other_statements
  576.  The delete statement is used to remove an element from an array.
  577.  The syntax is 'delete' keyword followed by array name, followed
  578.  by index value enclosed in square brackets ([]).
  579.  
  580.  The return statement is used in user-defined functions.  The syntax
  581.  is the keyword 'return' optionally followed by a string or numeric
  582.  expression.
  583.  
  584.  See also subtopic 'functions IO_functions' for a description of
  585.  'print', 'printf', and 'getline'.
  586. 3 fields
  587.  When an input record is read, it is automatically split into fields
  588.  based on the current values of FS (builtin variable defining field
  589.  separator expression) and RS (builtin variable defining record
  590.  separator character).  The default value of FS is an expression
  591.  which matches one or more spaces and tabs; the default for RS is
  592.  newline.  If the FIELDWIDTHS variable is set to a space separated
  593.  list of numbers (as in ``FIELDWIDTHS = "2 3 2"'') then the input
  594.  is treated as if it had fixed-width fields of the indicated sizes
  595.  and the FS value will be ignored.
  596.  
  597.  The field prefix operator ($), is used to reference a particular
  598.  field.  For example, $3 designates the third field of the current
  599.  record.  The entire record can be referenced via $0 (and it holds
  600.  the actual input record, not the values of $1, $2, ... concatenated
  601.  together, so multiple spaces--when present--remain intact, unless
  602.  a new value gets assigned).
  603.  
  604.  The builtin variable NF holds the number of fields in the current
  605.  record.  $NF is therefore the value of the last field.  Attempts to
  606.  access fields beyond NF result in null values (if a record contained
  607.  3 fields, the value of $5 would be "").
  608.  
  609.  Assigning a new value to $0 causes all the other field values (and NF)
  610.  to be re-evaluated.  Changing a specific field will cause $0 to receive
  611.  a new value once it's re-evaluated, but until then the other existing
  612.  fields remain unchanged.
  613. 3 variables
  614.  Variables in awk can hold both numeric and string values and do not
  615.  have to be pre-declared.  In fact, there is no way to explicitly
  616.  declare them at all.  Variable names consist of a leading letter
  617.  (either upper or lower case, which are distinct from each other)
  618.  or underscore (_) character followed by any number of letters,
  619.  digits, or underscores.
  620.  
  621.  When a variable that didn't previously exist is referenced, it is
  622.  created and given a null value.  A null value is treated as 0 when
  623.  used as a number, and is a string of zero characters in length if
  624.  used as a string.
  625. 4 builtin_variables
  626.  GAWK maintains several 'built-in' variables.  All have default values;
  627.  some are updated automatically.  All the builtins have uppercase-only
  628.  names.
  629.  
  630.  These builtin variables control how awk behaves
  631.    FS  input field separator; default is a single space, which is
  632.          treated as if it were a regular expression for matching
  633.          one or more spaces and/or tabs; a value of " " also has a
  634.          second special-case side-effect of causing leading blanks
  635.          to be ignored instead of producing a null first field;
  636.          initial value can be specified on the command line with
  637.          the -F option (or /field_separator); the value can be a
  638.          regular expression
  639.    RS  input record separator; default value is a newline ("\n");
  640.          only a single character is allowed [no regular expressions
  641.          or multi-character strings; expected to be remedied in a
  642.          future release of gawk]
  643.    OFS output field separator; value to place between variables in
  644.          a 'print' statement; default is one space; can be arbitrary
  645.          string
  646.    ORS output record separator; value to implicitly terminate 'print'
  647.          statement with; default is newline ("\n"); can be arbitrary
  648.          string
  649.    OFMT default output format used for printing numbers; default
  650.          value is "%.6g"
  651.    CONVFMT conversion format used for string-to-number conversions;
  652.          default value is also "%.6g", like OFMT
  653.    SUBSEP subscript separator for array indices; used when an array
  654.          subscript is specified as a comma separated list of values:
  655.          the comma is replaced by SUBSEP and the resulting index
  656.          is a concatenation of the values and SUBSEP(s); default
  657.          value is "\034"; value may be arbitrary string
  658.    IGNORECASE regular expression matching flag; if true (non-zero)
  659.          matching ignores differences between upper and lower case
  660.          letters; affects the '~' and '!~' operators, the 'index',
  661.          'match', 'split', 'sub', and 'gsub' functions, and the
  662.          field splitting based on FS; default value is false (0);
  663.          has no effect if GAWK is in strict compatibility mode (via
  664.          the -"W compat" option or /strict)
  665.    FIELDWIDTHS space or tab separated list of width sizes; takes
  666.          precedence over FS when set, but is cleared if FS has a
  667.          value assigned to it; [note: the current implementation
  668.          of fixed-field input is considered experimental and is
  669.          expected to evolve over time]
  670.  
  671.  These builtin variables provide useful information
  672.    NF  number of fields in the current record
  673.    NR  record number (accumulated over all files when more than one
  674.          input file is processed by the same program)
  675.    FNR current record number of the current input file; reset to 0
  676.          each time an input file is completed
  677.    RSTART starting position of substring matched by last invocation
  678.          of the 'match' function; set to 0 if a match fails and at
  679.          the start of each input record
  680.    RLENGTH length of substring matched by the last invocation of the
  681.          'match' function; set to -1 if a match fails
  682.    FILENAME name of the input file currently being processed; the
  683.          special name "-" is used to represent the standard input
  684.    ENVIRON array of miscellaneous user environment values; the VMS
  685.          implementation of GAWK provides values for ["USER"] (the
  686.          username), ["PATH"] (current default directory), ["HOME"]
  687.          (the user's login directory), and "[TERM]" (terminal type
  688.          if available) [all info provided by VAXCRTL's environ]
  689.    ARGC number of elements in the ARGV array, counting [0] which is
  690.          the program name (ie, "gawk")
  691.    ARGV array of command-line arguments (in [0] to [ARGC-1]); the
  692.          program name (ie, "gawk") in held in ARGV[0]; command line
  693.          parameters (data files and "var=value" expressions, but not
  694.          program options or the awk program text string if present)
  695.          are stored in ARGV[1] through ARGV[ARGC-1]; the awk program
  696.          can change values of ARGC and ARGV[] during execution in
  697.          order to alter which files are processed or which between-
  698.          file assignments are made
  699. 4 arrays
  700.  awk supports associative arrays to collect data into tables.  Array
  701.  elements can be either numeric or string, as can the indices used to
  702.  access them.  Each array must have a unique name, but a given array
  703.  can hold both string and numeric elements at the same time.  Arrays
  704.  are one-dimensional only, but multi-dimensional arrays can be
  705.  simulated using comma (,) separated indices, whereby a single index
  706.  value gets created by replacing commas with SUBSEP and concatenating
  707.  the resulting expression into a single string.
  708.  
  709.  Referencing an array element is done with the expression
  710.        Array[Index]
  711.  where 'Array' represents the array's name and 'Index' represents a
  712.  value or expression used for a subscript.  If the requested array
  713.  element did not exist, it will be created and assigned an initial
  714.  null value.  To check whether an element exists without creating it,
  715.  use the 'in' boolean operator.
  716.        Index in Array
  717.  would check 'Array' for element 'Index' and return 1 if it existed
  718.  or 0 otherwise.  To remove an element from an array, use the 'delete'
  719.  statement
  720.        delete Array[Index]
  721.  Note:  there is no way to delete an ordinary variable or an entire
  722.  array; 'delete' only works on a specific array element.
  723.  
  724.  To process all elements of an array (in succession) when their
  725.  subscripts might be unknown, use the 'in' variant of the for-loop
  726.        for (Index in Array) { ... }
  727. 3 functions
  728.  awk supports both built-in and user-defined functions.  A function
  729.  may be considered a 'black-box' which accepts zero or more input
  730.  parameters, performs some calculations or other manipulations based
  731.  on them, and returns a single result.
  732.  
  733.  The syntax for calling a function consists of the function name
  734.  immediately followed by an open parenthesis (left parenthesis '('),
  735.  followed by an argument list, followed by a closing parenthesis
  736.  (right parenthesis ')').  The argument list is a sequence of values
  737.  (numbers, strings, variables, array references, or expressions
  738.  involving the above and/or nested function calls), separated by
  739.  commas and optional white space.
  740.  
  741.  The parentheses are required punctuation, except for the 'print' and
  742.  'printf' builtin IO functions, where they're optional, and for the
  743.  builtin IO function 'getline', where they're not allowed.  Some
  744.  functions support optional [trailing] arguments which can be simply
  745.  omitted (along with the corresponding comma if applicable).
  746. 4 numeric_functions
  747.  Builtin numeric functions
  748.    int(n)      returns the value of 'n' with any fraction truncated
  749.                  [truncation of negative values is towards 0]
  750.    sqrt(n)     the square root of n
  751.    exp(n)      the exponential of n ('e' raised to the 'n'th power)
  752.    log(n)      natural logarithm of n
  753.    sin(n)      sine of n (in radians)
  754.    cos(n)      cosine of n (radians)
  755.    atan2(m,n)  arctangent of m/n (radians)
  756.    rand()      random number in the range 0 to 1 (exclusive)
  757.    srand(s)    sets the random number 'seed' to s, so that a sequence
  758.                  of 'random' numbers can be repeated; returns the
  759.                  previous seed value; srand() [argument omitted] sets
  760.                  the seed to an 'unpredictable' value (based on date
  761.                  and time, for instance, so should be unrepeatable)
  762. 4 string_functions
  763.  Builtin string functions
  764.    index(s,t)  search string s for substring t; result is 1-based
  765.                  offset of t within s, or 0 if not found
  766.    length(s)   returns the length of string s; either 'length()'
  767.                  with its argument omitted or 'length' without any
  768.                  parenthesized argument list will return length of $0
  769.    match(s,r)  search string s for regular expression r; the offset
  770.                  of the longest, left-most substring which matches
  771.                  is returned, or 0 if no match was found; the builtin
  772.                  variables RSTART and RLENGTH are also set [RSTART to
  773.                  the return value and RLENGTH to the size of the
  774.                  matching substring, or to -1 if no match was found]
  775.    split(s,a,f) break string s into components based on field
  776.                  separator f and store them in array a (into elements
  777.                  [1], [2], and so on); the last argument is optional,
  778.                  if omitted, the value of FS is used; the return value
  779.                  is the number of components found
  780.    sprintf(f,e,...) format expression(s) e using format string f and
  781.                  return the result as a string; formatting is similar
  782.                  to the printf function
  783.    sub(r,t,s)  search string target s for regular expression r, and
  784.                  if a match is found, replace the matching text with
  785.                  substring t, then store the result back in s; if s
  786.                  is omitted, use $0 for the string; the result is
  787.                  either 1 if a match+substitution was made, or 0
  788.                  otherwise; if substring t contains the character
  789.                  '&', the text which matched the regular expression
  790.                  is used instead of '&' [to suppress this feature
  791.                  of '&', 'quote' it with a backslash (\); since this
  792.                  will be inside a quoted string which will receive
  793.                  'backslash' processing before being passed to sub(),
  794.                  *two* consecutive backslashes will be needed "\\&"]
  795.    gsub(r,t,s) similar to sub(), but gsub() replaces all nonoverlapping
  796.                  substrings instead of just the first, and the return
  797.                  value is the number of substitutions made
  798.    substr(s,p,l) extract a substring l characters long starting at
  799.                  offset p in string s; l is optional, if omitted then
  800.                  the remainder of the string (p thru end) is returned
  801.    tolower(s)  return a copy of string s in which every uppercase
  802.                  letter has been converted into lowercase
  803.    toupper(s)  analogous to tolower(); convert lowercase to uppercase
  804. 4 time_functions
  805.  Builtin time functions
  806.    systime()   return the current time of day as the number of seconds
  807.                  since some reference point; on VMS the reference point
  808.                  is January 1, 1970, at 12 AM local time (not UTC)
  809.    strftime(f,t) format time value t using format f; if t is omitted,
  810.                  the default is systime()
  811. 5 time_formats
  812.  Formatting directives similar to the 'printf' & 'sprintf' functions
  813.  (each is introduced in the format string by preceding it with a
  814.  percent sign (%)); the directive is substituted by the corresponding
  815.  value
  816.    a   abbreviated weekday name (Sun,Mon,Tue,Wed,Thu,Fri,Sat)
  817.    A   full weekday name
  818.    b   abbreviated month name (Jan,Feb,...)
  819.    B   full month name
  820.    c   date and time (Unix-style "aaa bbb dd HH:MM:SS YYYY" format)
  821.    C   century prefix (19 or 20) [not century number, ie 20th]
  822.    d   day of month as two digit decimal number (01-31)
  823.    D   date in mm/dd/yy format
  824.    e   day of month with leading space instead of leading 0 ( 1-31)
  825.    E   ignored; following format character used
  826.    H   hour (24 hour clock) as two digit number (00-23)
  827.    h   abbreviated month name (Jan,Feb,...) [same as %b]
  828.    I   hour (12 hour clock) as two digit number (01-12)
  829.    j   day of year as three digit number (001-366)
  830.    m   month as two digit number (01-12)
  831.    M   minute as two digit number (00-59)
  832.    n   'newline' (ie, treat %n as \n)
  833.    O   ignored; following format character used
  834.    p   AM/PM designation for 12 hour clock
  835.    r   time in AM/PM format ("II:MM:SS p")
  836.    R   time without seconds ("HH:MM")
  837.    S   second as two digit number (00-59)
  838.    t   tab (ie, treat %t as \t)
  839.    T   time ("HH:MM:SS")
  840.    U   week of year (00-53) [first Sunday is first day of week 1]
  841.    V   date (VMS-style "dd-bbb-YYYY" with 'bbb' forced to uppercase)
  842.    w   weekday as decimal digit (0 [Sunday] through 6 [Saturday])
  843.    W   week of year (00-53) [first _Monday_ is first day of week 1]
  844.    x   date ("aaa bbb dd YYYY")
  845.    X   time ("HH:MM:SS")
  846.    y   year without century (00-99)
  847.    Y   year with century (19yy-20yy)
  848.    Z   time zone name (always "local" for VMS)
  849.    %   literal percent sign (%)
  850. 4 IO_functions
  851.  Builtin I/O functions
  852.    print x,... print the values of one or more expressions; if none
  853.                  are listed, $0 is used; parentheses are optional;
  854.                  when multiple values are printed, the current value
  855.                  of builtin OFS (default is 1 space) is used to
  856.                  separate them; the print line is implicitly
  857.                  terminated with the current value of ORS (default
  858.                  is newline); print does not have a return value
  859.    printf(f,x,...) print the values of one or more expressions, using
  860.                  the specified format string; null strings are used
  861.                  to supply missing values (if any); no between field
  862.                  or trailing newline characters are printed, they
  863.                  should be specified within the format string; the
  864.                  argument-enclosing parentheses are optional;
  865.                  printf does not have a return value
  866.    getline v   read a record into variable v; if v is omitted, $0 is
  867.                  used (and NF, NR, and FNR are updated); if v is
  868.                  specified, then field-splitting won't be performed;
  869.                  note:  parentheses around the argument are *not*
  870.                  allowed; return value is 1 for successful read, 0
  871.                  if end of file is encountered, or -1 if some sort
  872.                  of error occurred; [see 'redirection' for several
  873.                  variants]
  874.    close(s)    close a file or pipe specified by the string s; the
  875.                  string used should have the same value as the one
  876.                  used in a getline or print/printf redirection
  877.    system(s)   pass string s to executed by the operating system;
  878.                  the command string is executed in a subprocess
  879. 5 redirection
  880.  Both getline and print/printf support variant forms which use
  881.  redirection and pipes.
  882.  
  883.  To read from a file (instead of from the primary input file), use
  884.      getline var < "file"
  885.  or  getline < "file"    (read into $0)
  886.  where the string "file" represents either an actual file name (in
  887.  quotes) or a variable which contains a file name string value or an
  888.  expression which evaluates to a string filename.
  889.  
  890.  To create a pipe executing some command and read the result into
  891.  a variable (or into $0), use
  892.      "command" | getline var
  893.  or  "command" | getline    (read into $0)
  894.  where "command" is a literal string containing an operating system
  895.  command or a variable with a string value representing such a
  896.  command.
  897.  
  898.  To output into a file other that the primary output, use
  899.      print x,... > "file"    (or >> "file")
  900.  or  printf(f,x,...) > "file"    (or >> "file")
  901.  similar to the 'getline' example above.  '>>' causes output to be
  902.  appended to an existing file if it exists, or create the file if
  903.  it doesn't already exist.  '>' always creates a new file.  The
  904.  alternate redirection method of '>$' (for RMS text file attributes)
  905.  is *only* available on the command line, not with 'print' or
  906.  'printf' in  the current release.
  907.  
  908.  To output an error message, use 'print' or 'printf' and redirect
  909.  the output to file "/dev/stderr" (or equivalently to "SYS$ERROR:"
  910.  on VMS).  'stderr' will normally be the user's terminal, even if
  911.  ordinary output is being redirected into a file.
  912.  
  913.  To feed awk output into another command, use
  914.      print x,... | "command"    (similarly for 'printf')
  915.  similar to the second 'getline' example.  In this case, output
  916.  from awk will be passed as input to the specified operating system
  917.  command.  The command must be capable of reading input from 'stdin'
  918.  ("SYS$INPUT:" on VMS) in order to receive data in this manner.
  919.  
  920.  The 'close' function operates on the "file" or "command" argument
  921.  specified here (either a literal string or a variable or expression
  922.  resulting in a string value).  It completely closes the file or
  923.  pipe so that further references to the same file or command string
  924.  would re-open that file or command at the beginning.  Closing a
  925.  pipe or redirection also releases some file-oriented resources.
  926.  
  927.  Note:  the VMS implementation of GAWK uses temporary files to
  928.  simulate pipes, so a command must finish before 'getline' can get
  929.  any input from it, and 'close' must be called for an output pipe
  930.  before any data can be passed to the specified command.
  931. 5 formats
  932.  Formatting characters used by the 'printf' and 'sprintf' functions
  933.  (each is introduced in the format string by preceding it with a
  934.  percent sign (%))
  935.    %   include a literal percent sign (%) in the result
  936.    c   format the next argument as a single ASCII character
  937.          (prints first character of string argument, or corresponding
  938.          ASCII character if numeric argument, e.g. 65 is 'A')
  939.    s   format the next argument as a string (numeric arguments are
  940.          converted into strings on demand)
  941.    d   decimal number (ie, integer value in base 10)
  942.    i   integer (equivalent to decimal)
  943.    o   octal number (integer in base 8)
  944.    x   hexadecimal number (integer in base 16) [lowercase]
  945.    X   hexadecimal number [digits 'A' thru 'E' in uppercase]
  946.    f   floating point number (digits, decimal point, fraction digits)
  947.    e   exponential (scientific notation) number (digit, decimal
  948.          point, fraction digits, letter 'e', sign '+' or '-',
  949.          exponent digits)
  950.    g   'fractional' number in either 'e' or 'f' format, whichever
  951.          produces shorter result
  952.  
  953.  Three optional modifiers can be placed between the initiating
  954.  percent sign and the format character (doesn't apply to %%).
  955.    -   left justify (only matters when width specifier is present)
  956.    NN  width ['NN' represents 1 or more decimal digits]; actually
  957.          minimum width to use, longer items will not be truncated; a
  958.          leading 0 will cause right-justified numbers to be padded on
  959.          the left with zeroes instead of spaces when they're aligned
  960.    .MM precision [decimal point followed by 1 or more digits]; used
  961.          as maximum width for strings (causing truncation if they're
  962.          actually longer) or as number of fraction digits for 'f' or
  963.          'e' numeric formats, or number of significant digits for 'g'
  964.          numeric format
  965. 4 user_defined_functions
  966.  User-defined functions may be created as needed to simplify awk
  967.  programs or to collect commonly used code into one place.  The
  968.  general syntax of a user-defined function is the 'function' keyword
  969.  followed by unique function name, followed by a comma-separated
  970.  parameter list enclosed in parentheses, followed by statement(s)
  971.  enclosed within braces ({}).  A 'return' statement is customary
  972.  but is not required.
  973.        function FuncName(arg1,arg2) {
  974.            # arbitrary statements
  975.            return (arg1 + arg2) / 2
  976.        }
  977.  If a function does not use 'return' to specify an output value, the
  978.  result received by the caller will be unpredictable.
  979.  
  980.  Functions may be placed in an awk program before, between, or after
  981.  the pattern-action rules.  The abbreviation 'func' may be used in
  982.  place of 'function', unless POSIX compatibility mode is in effect.
  983. 3 regular_expressions
  984.  A regular expression is a shorthand way of specifying a 'wildcard'
  985.  type of string comparison.  Regular expression matching is very
  986.  fundamental to awk's operation.
  987.  
  988.  Meta symbols
  989.    ^   matches beginning of line or beginning of string; note that
  990.          embedded newlines ('\n') create multi-line strings, so
  991.          beginning of line is not necessarily beginning of string
  992.    $   matches end of line or end of string
  993.    .   any single character (except newline)
  994.    [ ] set of characters; [ABC] matches either 'A' or 'B' or 'C'; a
  995.          dash (other than first or last of the set) denotes a range
  996.          of characters: [A-Z] matches any upper case letter; if the
  997.          first character of the set is '^', then the sense of match
  998.          is reversed: [^0-9] matches any non-digit; several
  999.          characters need to be quoted with backslash (\) if they
  1000.          occur in a set:  '\', ']', '-', and '^'
  1001.    |   alternation (similar to boolean 'or'); match either of two
  1002.          patterns [for example "^start|stop$" matches leading 'start'
  1003.          or trailing 'stop']
  1004.    ( ) grouping, alter normal precedence [for example, "^(start|stop)$"
  1005.          matches lines reading either 'start' or 'stop']
  1006.    *   repeated matching; when placed after a pattern, indicates that
  1007.          the pattern should match any number of times [for example,
  1008.          "[a-z][0-9]*" matches a lower case letter followed by zero or
  1009.          more digits]
  1010.    +   repeated matching; when placed after a pattern, indicates that
  1011.          the pattern should match one or more times ["[0-9]+" matches
  1012.          any non-empty sequence of digits]
  1013.    ?   optional matching; indicates that the pattern can match zero or
  1014.          one times ["[a-z][0-9]?" matches lower case letter alone or
  1015.          followed by a single digit]
  1016.    \   quote; prevent the character which follows from having special
  1017.          meaning
  1018.  
  1019.  A regular expression which matches a string or line will match against
  1020.  the first (left-most) substring which meets the pattern and include
  1021.  the longest sequence of characters which still meets that pattern.
  1022. 3 comments
  1023.  Comments in awk programs are introduced with '#'.  Anything after
  1024.  '#' on a line is ignored by GAWK.  It's a good idea to include an
  1025.  explanation of what an awk program is doing and also who wrote it
  1026.  and when.
  1027. 3 further_information
  1028.  For complete documentation on GAWK, see "The_GAWK_Manual" from FSF.
  1029.  Source text for it is present in the file GAWK.TEXINFO.  A postscript
  1030.  version is available via anonymous FTP from host prep.ai.mit.edu in
  1031.  directory pub/gnu/.
  1032.  
  1033.  For additional documentation on awk--above and beyond that provided in
  1034.  The_GAWK_Manual--see "The_AWK_Programming_Language" by Aho, Weinberger,
  1035.  and Kernighan (2nd edition, 1988), published by Addison-Wesley.  It is
  1036.  both a reference on the awk language and a tutorial on awk's use, with
  1037.  many sample programs.
  1038. 3 authors
  1039.  The awk programming language was originally created by Alfred V. Aho,
  1040.  Peter J. Weinberger, and Brian W. Kernighan in 1977.  The language
  1041.  was revised and enhanced in a new version which was released in 1985.
  1042.  
  1043.  GAWK, the GNU implementation of awk, was written in 1986 by Paul Rubin
  1044.  and Jay Fenlason, with advice from Richard Stallman, and with
  1045.  contributions from John Woods.  In 1988 and 1989, David Trueman and
  1046.  Arnold Robbins revised GAWK for compatibility with the newer awk.
  1047.  
  1048.  GAWK version 2.11.1 was ported to VMS by Pat Rankin in November, 1989,
  1049.  with further revisions in the Spring of 1990.  The VMS port was
  1050.  incorporated into the official GNU distribution of version 2.13 in
  1051.  Spring 1991.  (Version 2.12 was never publically released.)
  1052. 2 release_notes
  1053.  GAWK 2.14 tested under VMS V5.5, July, 1992; compatible with VMS
  1054.  versions V4.6 and later.  Current source code compatible with DEC's
  1055.  VAXC v3.x and v2.4 or v2.3; also compiles successfully with GNUC
  1056.  (GNU's gcc).  VMS POSIX uses c89 and requires VAXC V3.x.
  1057. 3 AWK_LIBRARY
  1058.  GAWK uses a built in search path when looking for a program file
  1059.  specified by the -f option (or the /input qualifier) when that file
  1060.  name does not include a device and/or directory.  GAWK will first
  1061.  look in the current default directory, then if the file wasn't found
  1062.  it will look in the directory specified by the translation of logical
  1063.  name "AWK_LIBRARY".
  1064.  
  1065.  Not applicable under VMS POSIX.
  1066. 3 known_problems
  1067.  There are several known problems with GAWK running on VMS.  Some can
  1068.  be ignored, others require work-arounds.  Note: GAWK in the VMS POSIX
  1069.  environment does not have these problems.
  1070. 4 command_line_parsing
  1071.  The command
  1072.        gawk "program text"
  1073.  will pass the first phase of DCL parsing (the single required
  1074.  parameter is present), then it will give an error that a required
  1075.  element (either /input=awk_file or /commands="program text") is
  1076.  missing.  If what was intended (as is most likely) is to pass the
  1077.  program text to the UN*X-style command interface, the following
  1078.  variation is required
  1079.        gawk -- "program text"
  1080.  The presence of "--", which is normally optional, will inhibit the
  1081.  attempt to use DCL parsing (as will any '-' option or redirection).
  1082. 4 file_formats
  1083.  If a file having the RMS attribute "Fortran carriage control" is
  1084.  read as input, it will generate an empty first record if the first
  1085.  actual record begins with a space (leading space becomes a newline).
  1086.  Also, the last record of the file will give a "record not terminated"
  1087.  warning.  Both of these minor problems are due to the way that the
  1088.  C Run-Time Library (VAXCRTL) converts record attributes.
  1089.  
  1090.  Another poor feature without a work-around is that there's no way to
  1091.  specify "append if possible, create with RMS text attributes if not"
  1092.  with the current command line I/O redirection.  '>>$' isn't supported.
  1093. 4 RS_peculiarities
  1094.  Changing the record separator to something other than newline ('\n')
  1095.  will produce anomalous results for ordinary files.  For example,
  1096.  using RS = "\f" and FS = "\n" with the following input
  1097.        |rec 1, line 1
  1098.        |rec 1, line 2
  1099.        |^L    (form feed)
  1100.        |rec 2, line 1
  1101.        |rec 2, line 2
  1102.        |^L    (form feed)
  1103.        |rec 3, line 1
  1104.        |rec 3, line 2
  1105.        |(end of file)
  1106.  will produce two fields for record 1, but three fields each for
  1107.  records 2 and 3.  This is because the form-feed record delimiter is
  1108.  on its own line, so awk sees a newline after it.  Since newline is
  1109.  now a field separator, records 2 and 3 will have null first fields.
  1110.  The following awk code will work-around this problem by inserting
  1111.  a null first field in the first record, so that all records can be
  1112.  handled the same by subsequent processing.
  1113.        # fix up for first record (RS != "\n")
  1114.        FNR == 1  { if ( $0 == "" )     #leading separator
  1115.                      next              #skip its null record
  1116.                    else                #otherwise,
  1117.                      $0 = FS $0        #realign fields
  1118.                  }
  1119.  There is a second problem with this same example.  It will always
  1120.  trigger a "record not terminated" warning when it reaches the end of
  1121.  file.  In the sample shown, there is no final separator; however, if
  1122.  a trailing form-feed were present, it would produce a spurious final
  1123.  record with two null fields.  This occurs because the I/O system
  1124.  sees an implicit newline at the end of the last record, so awk sees
  1125.  a pair of null fields separated by that newline.  The following code
  1126.  fragment will fix that provided there are no null records (in this
  1127.  case, that would be two consecutive lines containing just form-feeds).
  1128.        # fix up for last record (RS != "\n")
  1129.        $0 == FS  { next }      #drop spurious final record
  1130.  Note that the "record not terminated" warning will persist.
  1131. 4 cmd_inconsistency
  1132.  The DCL qualifier /OUTPUT is internally equivalent to '>$' output
  1133.  redirection, but the qualifier /INPUT corresponds to the -f option
  1134.  rather than to '<' input redirection.
  1135. 4 exit
  1136.  The exit statement can optionally pass a final status value to the
  1137.  operating system.  GAWK expects a UN*X-style value instead of a
  1138.  VMS status value, so 0 indicates success and non-zero indicates
  1139.  failure.  The final exit status will be 1 (VMS success) if 0 is
  1140.  used, or even (VMS non-success) if non-zero is used.
  1141. 3 changes
  1142.  Changes between version 2.14 and 2.13.2:
  1143.  
  1144.    General
  1145.      'next file' construct added
  1146.      'continue' outside of any loop is treated as 'next'
  1147.      Assorted bug fixes and efficiency improvements
  1148.      _The_GAWK_Manual_ updated
  1149.      Test suite expanded
  1150.  
  1151.    VMS-specific
  1152.      VMS POSIX support added
  1153.      Disk I/O throughput enhanced
  1154.      Pipe emulation improved and incorrect interaction with user-mode
  1155.          redefinition of SYS$OUTPUT eliminated
  1156. 3 prior_changes
  1157.  Changes between version 2.13 and 2.11.1:  (2.12 was not released)
  1158.  
  1159.    General
  1160.      CONVFMT and FIELDWIDTHS builtin control variables added
  1161.      systime() and strftime() date/time functions added
  1162.      'lint' and 'posix' run-time options added
  1163.      '-W' command line option syntax supercedes '-c', '-C', and '-V'
  1164.      '-a' and '-e' regular expression options made obsolete
  1165.      Various bug fixes and efficiency improvements
  1166.      More platforms supported ('officially' including VMS)
  1167.  
  1168.    VMS-specific
  1169.      %g printf format fixed
  1170.      Handling of '\' on command line modified; no longer necessary to
  1171.          double it up
  1172.      Problem redirecting stderr (>&efile) at same time as stdin (<ifile)
  1173.          or stdout (>ofile) has been fixed
  1174.      ``2>&1'' and ``1>&2'' redirection constructs added
  1175.      Interaction between command line I/O redirection and gawk pipes
  1176.          fixed; also, name used for pseudo-pipe temporary file expanded
  1177. 3 license
  1178.  GAWK is covered by the "GNU General Public License", the gist of which
  1179.  is that if you supply this software to a third party, you are expressly
  1180.  forbidden to prevent them from supplying it to a fourth party, and if
  1181.  you supply binaries you must make the source code available to them
  1182.  at no additional cost.  Any revisions or modified versions are also
  1183.  covered by the same license.  There is no warranty, express or implied,
  1184.  for this software.  It is provided "as is."
  1185.  
  1186.  [Disclaimer:  This is just an informal summary with no legal basis;
  1187.  refer to the actual GNU General Public License for specific details.]
  1188. !2 examples
  1189. !
  1190.