gawk: Long

1 
1 1.1.3 Running Long Programs
1 ---------------------------
1 
1 Sometimes 'awk' programs are very long.  In these cases, it is more
1 convenient to put the program into a separate file.  In order to tell
1 'awk' to use that file for its program, you type:
1 
1      awk -f SOURCE-FILE INPUT-FILE1 INPUT-FILE2 ...
1 
1    The '-f' instructs the 'awk' utility to get the 'awk' program from
1 the file SOURCE-FILE (⇒Options).  Any file name can be used for
1 SOURCE-FILE.  For example, you could put the program:
1 
1      BEGIN { print "Don't Panic!" }
1 
1 into the file 'advice'.  Then this command:
1 
1      awk -f advice
1 
1 does the same thing as this one:
1 
1      awk 'BEGIN { print "Don\47t Panic!" }'
1 
1 This was explained earlier (⇒Read Terminal).  Note that you don't
1 usually need single quotes around the file name that you specify with
1 '-f', because most file names don't contain any of the shell's special
1 characters.  Notice that in 'advice', the 'awk' program did not have
1 single quotes around it.  The quotes are only needed for programs that
1 are provided on the 'awk' command line.  (Also, placing the program in a
1 file allows us to use a literal single quote in the program text,
1 instead of the magic '\47'.)
1 
1    If you want to clearly identify an 'awk' program file as such, you
1 can add the extension '.awk' to the file name.  This doesn't affect the
1 execution of the 'awk' program but it does make "housekeeping" easier.
1