Go to the first, previous, next, last section, table of contents.
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 equals sign (`=') and the argument's value, or the keyword and the argument's value are separated by whitespace. If a particular option with a value is given more than once, it is the last value that counts.
Each long option for @command{gawk} has a corresponding POSIX-style option. The long and short options are interchangeable in all contexts. The options and their meanings are as follows:
-F fs
--field-separator fs
FS variable to fs
(see section Specifying How Fields Are Separated).
-f source-file
--file source-file
-v var=val
--assign var=val
BEGIN rule
(see section Other Command-Line Arguments).
The @option{-v} option can only set one variable, but it can be used
more than once, setting another variable each time, like this:
`awk -v foo=1 -v bar=2 ...'.
Caution: Using @option{-v} to set the values of the built-in
variables may lead to surprising results. @command{awk} will reset the
values of those variables as it needs to, possibly ignoring any
predefined value you may have given.
-mf N
-mr N
-W gawk-opt
--
The previous list described options mandated by the POSIX standard, as well as options available in the Bell Laboratories version of @command{awk}. The following list describes @command{gawk}-specific options:
-W compat
-W traditional
--compat
--traditional
-W copyright
--copyright
-W copyleft
--copyleft
-W dump-variables[=file]
--dump-variables[=file]
i, j, and so on.)
-W gen-po
--gen-po
gettext Portable Object file on standard
output for all string constants that have been marked for translation.
@xref{Internationalization, ,Internationalization with @command{gawk}},
for information about this option.
-W help
-W usage
--help
--usage
-W lint[=fatal]
--lint[=fatal]
-W lint-old
--lint-old
-W non-decimal-data
--non-decimal-data
-W posix
--posix
\x escape sequences are not recognized
(see section Escape Sequences).
FS is
equal to a single space
(see section Examining Fields).
func for the keyword function is not
recognized (see section Function Definition Syntax).
FS to be a single tab character
(see section Specifying How Fields Are Separated).
fflush built-in function is not supported
(see section Input/Output Functions).
-W profile[=file]
--profile[=file]
-W re-interval
--re-interval
-W source program-text
--source program-text
-W version
--version
As long as program text has been supplied, any other options are flagged as invalid with a warning message but are otherwise ignored.
In compatibility mode, as a special case, if the value of fs supplied
to the @option{-F} option is `t', then FS is set to the tab
character ("\t"). This is only true for @option{--traditional} and not
for @option{--posix}
(see section Specifying How Fields Are Separated).
The @option{-f} option may be used more than once on the command-line. If it is, @command{awk} reads its program source from all of the named files, as if they had been concatenated together into one big file. This is useful for creating libraries of @command{awk} functions. These functions can be written once and then retrieved from a standard place, instead of having to be included into each individual program. (As mentioned in section Function Definition Syntax, function names must be unique.)
Library functions can still be used, even if the program is entered at the terminal, by specifying `-f /dev/tty'. After typing your program, type Ctrl-d (the end-of-file character) to terminate it. (You may also use `-f -' to read program source from the standard input but then you will not be able to also use the standard input as a source of data.)
Because it is clumsy using the standard @command{awk} mechanisms to mix source file and command-line @command{awk} programs, @command{gawk} provides the @option{--source} option. This does not require you to pre-empt the standard input for your source code; it allows you to easily mix command-line and library source code (@pxref{AWKPATH Variable, ,The @env{AWKPATH} Environment Variable}).
If no @option{-f} or @option{--source} option is specified, then @command{gawk} uses the first non-option command-line argument as the text of the program source code.
If the environment variable @env{POSIXLY_CORRECT} exists, then @command{gawk} behaves in strict POSIX mode, exactly as if you had supplied the @option{--posix} command-line option. Many GNU programs look for this environment variable to turn on strict POSIX mode. If @option{--lint} is supplied on the command-line and @command{gawk} turns on POSIX mode because of @env{POSIXLY_CORRECT}, then it issues a warning message indicating that POSIX mode is in effect. You would typically set this variable in your shell's startup file. For a Bourne-compatible shell (such as @command{bash}), you would add these lines to the `.profile' file in your home directory:
POSIXLY_CORRECT=true export POSIXLY_CORRECT
For a @command{csh} compatible shell,(48) you would add this line to the `.login' file in your home directory:
setenv POSIXLY_CORRECT true
Having @env{POSIXLY_CORRECT} set is not recommended for daily use, but it is good for testing the portability of your programs to other environments.
Go to the first, previous, next, last section, table of contents.