Contents | < Browse | Browse >
Running Long Programs
---------------------
Sometimes your `awk' programs can be very long. In this case it is
more convenient to put the program into a separate file. To tell `awk'
to use that file for its program, you type:
awk -f SOURCE-FILE INPUT-FILE1 INPUT-FILE2 ...
The `-f' instructs the `awk' utility to get the `awk' program from
the file SOURCE-FILE. Any file name can be used for SOURCE-FILE. For
example, you could put the program:
/th/
into the file `th-prog'. Then this command:
awk -f th-prog
does the same thing as this one:
awk '/th/'
which was explained earlier (Read Terminal).
Note that you don't usually need single quotes around
the file name that you specify with `-f', because most file names don't
contain any of the shell's special characters. Notice that in
`th-prog', the `awk' program did not have single quotes around it. The
quotes are only needed for programs that are provided on the `awk'
command line.
If you want to identify your `awk' program files clearly as such,
you can add the extension `.awk' to the file name. This doesn't affect
the execution of the `awk' program, but it does make "housekeeping"
easier.