gawk: Pattern Action Summary

1 
1 7.6 Summary
1 ===========
1 
1    * Pattern-action pairs make up the basic elements of an 'awk'
1      program.  Patterns are either normal expressions, range
1      expressions, or regexp constants; one of the special keywords
1      'BEGIN', 'END', 'BEGINFILE', or 'ENDFILE'; or empty.  The action
1      executes if the current record matches the pattern.  Empty
1      (missing) patterns match all records.
1 
1    * I/O from 'BEGIN' and 'END' rules has certain constraints.  This is
1      also true, only more so, for 'BEGINFILE' and 'ENDFILE' rules.  The
1      latter two give you "hooks" into 'gawk''s file processing, allowing
1      you to recover from a file that otherwise would cause a fatal error
1      (such as a file that cannot be opened).
1 
1    * Shell variables can be used in 'awk' programs by careful use of
1      shell quoting.  It is easier to pass a shell variable into 'awk' by
1      using the '-v' option and an 'awk' variable.
1 
1    * Actions consist of statements enclosed in curly braces.  Statements
1      are built up from expressions, control statements, compound
1      statements, input and output statements, and deletion statements.
1 
1    * The control statements in 'awk' are 'if'-'else', 'while', 'for',
1      and 'do'-'while'.  'gawk' adds the 'switch' statement.  There are
1      two flavors of 'for' statement: one for performing general looping,
1      and the other for iterating through an array.
1 
1    * 'break' and 'continue' let you exit early or start the next
1      iteration of a loop (or get out of a 'switch').
1 
1    * 'next' and 'nextfile' let you read the next record and start over
1      at the top of your program or skip to the next input file and start
1      over, respectively.
1 
1    * The 'exit' statement terminates your program.  When executed from
1      an action (or function body), it transfers control to the 'END'
1      statements.  From an 'END' statement body, it exits immediately.
1      You may pass an optional numeric value to be used as 'awk''s exit
1      status.
1 
1    * Some predefined variables provide control over 'awk', mainly for
1      I/O. Other variables convey information from 'awk' to your program.
1 
1    * 'ARGC' and 'ARGV' make the command-line arguments available to your
1      program.  Manipulating them from a 'BEGIN' rule lets you control
1      how 'awk' will process the provided data files.
1