Go to the first, previous, next, last section, table of contents.
Sometimes your @command{awk} programs can be very long. In this case, it is more convenient to put the program into a separate file. In order to tell @command{awk} to use that file for its program, you type:
awk -f source-file input-file1 input-file2 ...
The @option{-f} instructs the @command{awk} utility to get the @command{awk} program from the file source-file. Any file name can be used for source-file. For example, you could put the program:
BEGIN { print "Don't Panic!" }
into the file `advice'. Then this command:
awk -f advice
does the same thing as this one:
awk "BEGIN { print \"Don't Panic!\" }"
This was explained earlier (@pxref{Read Terminal, ,Running @command{awk} Without Input Files}). Note that you don't usually need single quotes around the file name that you specify with @option{-f}, because most file names don't contain any of the shell's special characters. Notice that in `advice', the @command{awk} program did not have single quotes around it. The quotes are only needed for programs that are provided on the @command{awk} command line.
If you want to identify your @command{awk} program files clearly as such, you can add the extension `.awk' to the file name. This doesn't affect the execution of the @command{awk} program but it does make "housekeeping" easier.
Go to the first, previous, next, last section, table of contents.