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