z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Applying more than one instruction

z/OS UNIX System Services User's Guide
SA23-2279-00

When an awk program contains several instructions, awk applies every appropriate instruction to the first record, then every appropriate instruction to the second record, and so on. Instructions are applied in order. For example, consider the following awk program, which has two instructions:
$1 == "Linda"
$2 == "bridge" { print $1 }
The output of this program is:
Jim
Linda   bridge           12      30.00
Linda
Linda   cartooning        5      75.00
Lori
awk looks through the file record by record. The first record to satisfy one of the patterns is:
Jim     bridge            4      10.00
so awk prints the first field of the record (as dictated by the second instruction). The next record of interest is:
Linda   bridge           12      30.00
This satisfies the first instruction's pattern, so the whole record is printed. It also satisfies the second instruction's pattern, so the first field is printed. awk continues through the file, record by record, executing the appropriate actions when a record satisfies the pattern.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014