- Pattern–action pairs make up the basic elements of an
program. Patterns are either normal expressions, range expressions,
or regexp constants; one of the special keywords
ENDFILE; or empty. The action executes if
the current record matches the pattern. Empty (missing) patterns match
- I/O from
END rules has certain constraints.
This is also true, only more so, for
rules. The latter two give you “hooks” into
processing, allowing you to recover from a file that otherwise would
cause a fatal error (such as a file that cannot be opened).
- Shell variables can be used in
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
- Actions consist of statements enclosed in curly braces. Statements
are built up from expressions, control statements, compound statements,
input and output statements, and deletion statements.
- The control statements in
switch statement. There are two flavors of
statement: one for performing general looping, and the other for iterating
through an array.
continue let you exit early or start the next
iteration of a loop (or get out of a
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
awk’s exit status.
- Some predefined variables provide control over
awk, mainly for I/O.
Other variables convey information from
awk to your program.
ARGV make the command-line arguments available
to your program. Manipulating them from a
BEGIN rule lets you
awk will process the provided data files.