Chapter 11. Running awk and gawk
This chapter covers how to run awk, both POSIX-standard and gawk-specific command-line options, and what awk and gawk do with non-option arguments. It then proceeds to cover how gawk searches for source files, obsolete options and/or features, and known bugs in gawk. This chapter rounds out the discussion of awk as a program and as a language.
While a number of the options and features described here were discussed in passing earlier in the book, this chapter provides the full details.
Invoking awk
There are two ways to run awk -- with an explicit program or with one or more program files. Here are templates for both of them; items enclosed in [...] in these templates are optional:
awk [options
] -f progfile [--]file
... awk [options
] [--] 'program
'file
...
Besides traditional one-letter POSIX-style options, gawk also supports GNU long options.
It is possible to invoke awk with an empty program:
awk '' datafile1 datafile2
Doing so makes little sense, though; awk exits
silently when given an empty program. If
--lint
has been specified on the command line,
gawk issues a warning that the program is empty.
Command-Line Options
Options begin with a dash and consist of a single character. GNU-style long options consist of two dashes and a keyword. The keyword can be abbreviated, as long as the abbreviation allows the option to be uniquely identified. If the option takes an argument, then the keyword is either immediately followed by an ...
Get Effective awk Programming, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.