home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gawk213s.lzh / GAWK213S / GAWK.HLP < prev    next >
Text File  |  1993-07-29  |  59KB  |  1,157 lines

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