manpagez: man pages & more
info gawk
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1.3 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. In order 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:

 
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 (see section Running awk Without Input Files). 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 ‘advice’, 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 clearly identify your awk program files 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.