a

awk(1)

awk(1)

A pattern can consist of two patterns separated by a comma; in this case, the action is performed for all lines from an occurrence of the ®rst pattern though an occurrence of the second.

A relational expression is one of the following:

expression matchop regular-expression expression relop expression expression in array-name (expr,expr,...) in array-name

where a relop is any of the six relational operators in C, and a matchop is either Ä (matches) or (does not match). A conditional is an arithmetic expression, a relational expression, or a Boolean combination of the two.

The special patterns BEGIN and END can be used to capture control before the ®rst input line is read and after the last. BEGIN and END do not combine with other patterns.

Special Characters

The following special escape sequences are recognized by awk in both regular expressions and strings:

Escape

Meaning

 

 

\a

alert character

 

\b

backspace character

 

\f

form-feed character

 

\n

new-line character

 

\r

carriage-return character

 

\t

tab character

 

 

\v

vertical-tab character

 

\nnn

1- to 3-digit octal value nnn

 

\xhhh 1- to n-digit hexadecimal number

 

Variable Names

 

 

 

 

Variable names with special meanings are:

 

FS

 

Input ®eld separator regular expression; a space character by default; also settable

 

 

by option -Ffs.

 

NF

 

The number of ®elds in the current record.

NR

 

The ordinal number of the current record from the start of input. Inside a BEGIN

 

 

action the value is zero. Inside an

END action the value is the number of the last

 

 

record processed.

 

FNR

 

The ordinal number of the current record in the current ®le. Inside a BEGIN

 

 

action the value is zero. Inside an

END action the value is the number of the last

 

 

record processed in the last ®le processed.

FILENAME

A pathname of the current input ®le.

RS

 

The input record separator; a newline character by default.

OFS

 

The

print statement output ®eld separator; a space character by default.

ORS

 

The

print statement output record separator; a newline character by default.

OFMT

 

Output format for numbers (default %.6g). If the value of OFMT is not a

 

 

¯oating-point format speci®cation, the results are unspeci®ed.

CONVFMT

 

Internal conversion format for numbers (default %.6g). If the value of CONVFMT

 

 

is not a ¯oating-point format speci®cation, the results are unspeci®ed.

SUBSEP

 

The subscript separator string for multi-dimensional arrays; the default value is

 

 

"\034"

 

ARGC

 

The number of elements in the ARGV array.

ARGV

 

An array of command line arguments, excluding options and the program argu-

 

 

ment numbered from zero to ARGC-1.

 

 

The arguments in ARGV can be modi®ed or added to; ARGC can be altered. As

 

 

each input ®le ends, awk will treat the next non-null element of ARGV, up to the

 

 

current value of ARGC-1, inclusive, as the name of the next input ®le. Thus, setting

Section 136

 

 

− 3 −

HP-UX Release 11i: December 2000