Go to the first, previous, next, last section, table of contents.
An @command{awk} program or script consists of a series of rules and function definitions interspersed. (Functions are described later. See section User-Defined Functions.) A rule contains a pattern and an action, either of which (but not both) may be omitted. The purpose of the action is to tell @command{awk} what to do once a match for the pattern is found. Thus, in outline, an @command{awk} program generally looks like this:
[pattern] [{ action }]
[pattern] [{ action }]
...
function name(args) { ... }
...
An action consists of one or more @command{awk} statements, enclosed in curly braces (`{' and `}'). Each statement specifies one thing to do. The statements are separated by newlines or semicolons. The curly braces around an action must be used even if the action contains only one statement, or if it contains no statements at all. However, if you omit the action entirely, omit the curly braces as well. An omitted action is equivalent to `{ print $0 }':
/foo/ { } match foo, do nothing -- empty action
/foo/ match foo, print the record -- omitted action
The following types of statements are supported in @command{awk}:
if, for, while, and do) as well as a few
special ones (see section Control Statements in Actions).
if, while, do,
or for statement.
getline command
(see section Explicit Input with getline), the next
statement (see section The next Statement),
and the nextfile statement
(@pxref{Nextfile Statement, ,Using @command{gawk}'s nextfile Statement}).
print and printf.
See section Printing Output.
delete Statement.
Go to the first, previous, next, last section, table of contents.