Program files
A program file is a text file that contains an awk program.
You can create program files with any text editor (such as ed).
For example, you might create a file named lbprog.awk that
contains the lines:
$1 == "Linda"
$2 == "bridge" { print $1 }
To execute a program on a particular
data file, use the command:
awk –f progfile
datafile
where progfile is the name
of the file that contains the awk program, and datafile is the name of the data file. For example:
awk –f lbprog.awk hobbies
runs
the program in lbprog.awk on the data in hobbies.If the data file does not use the default separator characters,
you must specify a –F option after the progfile name,
as in:
awk –f prog.awk –F":" file.dat
To gain some experience using awk, you can test the examples on the hobbies file. Run some from the command line and some from program files.