MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
awk actually creates ARGC and ARGV before doing anything else. It then walks through
ARGV processing the arguments. If an element of ARGV is an empty string, awk skips it. If it
contains an equals sign (=), awk interprets it as a variable assignment. If it is a minus sign (-
-), awk immediately reads input from the standard input until it encounters the end-of-file;
otherwise, awk treats the argument as a file name and reads input from that file until it reaches
end-of-file.
Note: awk runs the program by walking through ARGV in this way; thus if the program
changes ARGV, awk can read different files and make different assignments.
Input
awk divides input into records. A record separator character separates each record from the
next. The value of the built-in variable RS gives the current record separator character; by
default, it begins as the newline (\n). If you assign a different character to RS, awk uses that
as the record separator character from that point on.
awk divides records into fields. A field separator string, given by the value of the built-in
variable FS, separates each field from the next. You can set a specific separator string by
assigning a value to FS, or by specifying the –F ere option on the command line. You can
assign a regular expression to FS. For example,
FS = "[,:$]"
says that commas, colons, or dollar signs can separate fields. As a special case, assigning FS a
string containing only a blank character sets the field separator to white space. In this case,
awk considers any sequence of contiguous space and/or tab characters a single field separator.
This is the default for FS; however, if you assign FS a string containing any other character,
that character designates the start of a new field. For example, if we set FS="\t" (the tab
character),
texta \t textb \t \t \t textc
contains five fields, two of which only contain blanks. With the default setting, this record
only contains three fields, since awk considers the sequence of multiple blanks and tabs a
single separator.
The following list of built-in variables provides various pieces of information about input.
NF number of fields in the current record
NR number of records read so far
FILENAME name of file containing current record
FNR number of records read from current file
1-24 Commands and Utilities