An awk program consists of one or more program lines containing a pattern and/or action in the following format:
| pattern { action } |
The pattern selects lines from the input file. The awk utility
performs the action on all lines that the pattern selects. You must
enclose the action within braces so that awk can differentiate
it from the pattern. There are two rules which occur if either a
pattern or action is ommited:
To start, awk compares the first line in the input file with each pattern in the program. If a pattern selects a line (if there is a match), awk takes the action associated with the pattern. If the line is not selected, awk takes no action. When awk has completed its comparisons for the first line of the input file, it repeats the process for the next line of input. It continues this process, comparing subsequent lines in the input file, until it has read the entire input file/s.
If several patterns select the same line, awk takes the actions associated with each of the patterns in the order they appear. It is therefore possible for awk to send a single line from the input file to its standad output more than once.