Go to the first, previous, next, last section, table of contents.


Pattern Summary

awk patterns may be one of the following:

/regular expression/
relational expression
pattern && pattern
pattern || pattern
pattern ? pattern : pattern
(pattern)
! pattern
pattern1, pattern2
BEGIN
END

BEGIN and END are two special kinds of patterns that are not tested against the input. The action parts of all BEGIN rules are concatenated as if all the statements had been written in a single BEGIN rule. They are executed before any of the input is read. Similarly, all the END rules are concatenated, and executed when all the input is exhausted (or when an exit statement is executed). BEGIN and END patterns cannot be combined with other patterns in pattern expressions. BEGIN and END rules cannot have missing action parts.

For /regular-expression/ patterns, the associated statement is executed for each input record that matches the regular expression. Regular expressions are summarized below.

A relational expression may use any of the operators defined below in the section on actions. These generally test whether certain fields match certain regular expressions.

The `&&', `||', and `!' operators are logical "and," logical "or," and logical "not," respectively, as in C. They do short-circuit evaluation, also as in C, and are used for combining more primitive pattern expressions. As in most languages, parentheses may be used to change the order of evaluation.

The `?:' operator is like the same operator in C. If the first pattern matches, then the second pattern is matched against the input record; otherwise, the third is matched. Only one of the second and third patterns is matched.

The `pattern1, pattern2' form of a pattern is called a range pattern. It matches all input lines starting with a line that matches pattern1, and continuing until a line that matches pattern2, inclusive. A range pattern cannot be used as an operand of any of the pattern operators.

See section Pattern Elements.


Go to the first, previous, next, last section, table of contents.