5.8. awk Commands in a Script File

When you have multiple awk pattern/action statements, it is often much easier to put the statements in a script. The script is a file containing awk comments and statements. If statements and actions are on the same line, they are separated by semicolons. If statements are on separate lines, semicolons are not necessary. If an action follows a pattern, the opening curly brace must be on the same line as the pattern. Comments are preceded by a pound (#) sign.

Example 5.28.
% cat employees
					Tom Jones:4424:5/12/66:54335
					Mary Adams:5346:11/4/63:28765
					Billy Black:1683:9/23/44:336500
					Sally Chang:1654:7/22/54:65000
					Jose Tomas:1683:9/23/44:33650

(The Awk Script)
% cat info
1   # My first awk script by Jack Sprat
					# Script ...

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.