Open System Services Shell and Utilities Reference Manual (G06.25+, H06.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=expression
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 elds, input white space is not preserved in the output.
The le and command arguments can be literal names or expressions enclosed in parentheses.
Identical string values in different statements refer to the same open le.
The print statement writes its arguments to standard output (or to a le if > le or >> le is
present), separated by the current output eld separator and terminated by the current output
record separator.
The printf statement writes its arguments to standard output (or to a le if >le or >>le is
present, or to a pipe if | command is present), separated by the current output eld separator, and
terminated by the output record separator. le and command can be literal names or
parenthesized expressions. Identical string values in different statements denote the same open
le. You can redirect the output into a le using the print ... > le or printf ( ... ) > le state-
ments. The printf statement formats its expression list according to the format of the printf()
subroutine.
122 Hewlett-Packard Company 527188-003