MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
The –v option lets you assign a value to a variable before the awk program begins running
(that is, before the BEGIN action). For example, in
awk -v v1=10 -f prog datafile
awk assigns the variable v1 its value before the BEGIN action of the program (but after
default assignments made to built-in variables like FS, and OFMT; these built-in variables
have special meaning to awk, as described in later sections).
awk divides input into records. By default, newline characters separate records; however, you
may specify a different record separator if you want.
One at a time, and in order, awk compares each input record with the pattern of every rule in
the program. When a pattern matches, awk performs the action part of the rule on that input
record. Patterns and actions often refer to separate fields within a record. By default, white
space (usually blanks, newlines, or horizontal tab characters) separates fields; however, you
can specify a different field separator string using the –F ere option (see Input).
You can omit the pattern or action part of an awk rule (but not both). If you omit pattern,
awk performs the action on every input record (that is, every record matches). If you omit
action, awk writes every record matching the pattern to the standard output.
awk considers everything after a # in a program line to be a comment. For example:
# This is a comment
To continue program lines on the next line, add a backslash (\) to the end of the line. State-
ment lines ending with a comma (,), double or-bars (||), or double ampersands (&&) con-
tinue automatically on the next line.
Options
awk accepts the following options:
–F ere specifies an extended regular expression to use as the field separator.
–f prog
runs the awk program contained in the file prog. When more than one –f option
appears on the command line, the resulting program is a concatenation of all pro-
grams you specify.
–v var=value
assigns value to var before running the program. You can specify this option a num-
ber of times.
1-18 Commands and Utilities