Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)

awk(1) OSS Shell and Utilities Reference Manual
Pattern-Action Statements
Pattern-action statements follow the form:
pattern {action}
If a pattern lacks a corresponding action, awk writes the entire line that contains the pattern to
standard output. If an action lacks a corresponding pattern, awk applies the action to every line.
Actions
An action is a sequence of statements that follow C language syntax. These statements can
include:
if (expression) statement [ else statement ]
while (expression) statement
for (expression;expression;expression) statement
for (variable in array) statement
break
continue
{ [ statement ... ] }
variable=e xpression
print [ expression_list ][>file ][| command ]
printf format[ ,expression_list ][>file | >>file | | command ]
next
exit [ expression ]
delete array [ expression ]
Statements can end with a semicolon, a newline character, or the right brace enclosing the action.
Expressions can have string or numeric values and are built using the operators +, -,,/, %, and ˆ
(exponentiation), a space for string concatenation, and the C operators ++, --, +=
, -=,,/=, %=, ˆ=,
*=, >, >=, <, <=, ==, !=,
and ?:.
Because the actions process fields, input white space is not preserved in the output.
The file and command arguments can be literal names or expressions enclosed in parentheses.
Identical string values in different statements refer to the same open file.
The print statement writes its arguments to standard output (or to a file if > file or >> file is
present), separated by the current output field separator and terminated by the current output
record separator.
The printf statement writes its arguments to standard output (or to a file if >file or >>file is
present, or to a pipe if | command is present), separated by the current output field separator, and
terminated by the output record separator. file and command can be literal names or
parenthesized expressions. Identical string values in different statements denote the same open
file. You can redirect the output into a file using the print ... > file or printf ( ... ) > file state-
ments. The printf statement formats its expression list according to the format of the printf()
subroutine.
122 Hewlett-Packard Company 527188-021