Whats does -f mean in Interpretor Definition : !#/bin/awk -f
The -f
command line option for awk
specifies that the next argument should be the file to read the commands from.
If you omit the -f
, the interpreter will try to invoke your script using /bin/awk yourScriptFile
which will fail, e.g.:
$ cat yourScriptFile #!/bin/awk{ print $1; }$ ./yourScriptFile awk: cmd. line:1: ./yourScriptFileawk: cmd. line:1: ^ syntax errorawk: cmd. line:1: ./yourScriptFileawk: cmd. line:1: ^ unterminated regexp
See the POSIX documentation for awk (http://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html) or man 1 awk
for details.
From AWK man page.
-f progfile
awk uses the set of patterns it reads from progfile.
This means that the script must be found in progfile.
Quoting from man awk
:
-f file Program text is read from file instead of from the command line. Multiple -f options are allowed.
Here is an example:
Giving awk a program using -f filename
$ cat script.awk {print}$ awk -f script.awk <<< "abcd"abcd
Or creating an awk executable like this:
$ cat script1.awk #!/usr/bin/awk -f{print}$ ./script1.awk <<< "abcd"abcd