Gawk/Pattern-Overview
From Get docs
Next: Using Shell Variables, Up: Patterns and Actions [Contents][Index]
7.1 Pattern Elements
| • Regexp Patterns | Using regexps as patterns. | |
| • Expression Patterns | Any expression can be used as a pattern. | |
| • Ranges | Pairs of patterns specify record ranges. | |
| • BEGIN/END | Specifying initialization and cleanup rules. | |
| • BEGINFILE/ENDFILE | Two special patterns for advanced control. | |
| • Empty | The empty pattern, which matches every record. |
Patterns in awk control the execution of rules—a rule is
executed when its pattern matches the current input record.
The following is a summary of the types of awk patterns:
/regular expression/- A regular expression. It matches when the text of the input record fits the regular expression. (See section Regular Expressions.)
expression- A single expression. It matches when its value is nonzero (if a number) or non-null (if a string). (See section Expressions as Patterns.)
begpat, endpat- A pair of patterns separated by a comma, specifying a range of records. The range includes both the initial record that matches
begpatand the final record that matchesendpat. (See section Specifying Record Ranges with Patterns.) BEGIN
END
- Special patterns for you to supply startup or cleanup actions for your
awkprogram. (See section TheBEGINandENDSpecial Patterns.) BEGINFILE
ENDFILE
- Special patterns for you to supply startup or cleanup actions to be done on a per-file basis. (See section The
BEGINFILEandENDFILESpecial Patterns.) empty- The empty pattern matches every input record. (See section The Empty Pattern.)
Next: Using Shell Variables, Up: Patterns and Actions [Contents][Index]