Go forward to AWKPATH Variable.
Go backward to Options.
Go up to Command Line.
Other Command Line Arguments
============================
Any additional arguments on the command line are normally treated as
input files to be processed in the order specified. However, an
argument that has the form `VAR=VALUE', means to assign the value VALUE
to the variable VAR--it does not specify a file at all.
All these arguments are made available to your `awk' program in the
`ARGV' array (see Built-in Variables.). Command line options and
the program text (if present) are omitted from the `ARGV' array. All
other arguments, including variable assignments, are included.
The distinction between file name arguments and variable-assignment
arguments is made when `awk' is about to open the next input file. At
that point in execution, it checks the "file name" to see whether it is
really a variable assignment; if so, `awk' sets the variable instead of
reading a file.
Therefore, the variables actually receive the specified values after
all previously specified files have been read. In particular, the
values of variables assigned in this fashion are *not* available inside
a `BEGIN' rule (see `BEGIN' and `END' Special Patterns: BEGIN/END.),
since such rules are run before `awk' begins scanning the argument list.
The values given on the command line are processed for escape sequences
(see Constant Expressions: Constants.).
In some earlier implementations of `awk', when a variable assignment
occurred before any file names, the assignment would happen *before*
the `BEGIN' rule was executed. Some applications came to depend upon
this "feature." When `awk' was changed to be more consistent, the `-v'
option was added to accommodate applications that depended upon this
old behavior.
The variable assignment feature is most useful for assigning to
variables such as `RS', `OFS', and `ORS', which control input and
output formats, before scanning the data files. It is also useful for
controlling state if multiple passes are needed over a data file. For
example:
awk 'pass == 1 { PASS 1 STUFF }
pass == 2 { PASS 2 STUFF }' pass=1 datafile pass=2 datafile
Given the variable assignment feature, the `-F' option is not
strictly necessary. It remains for historical compatibility.