Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (a - b) awk(1)
NAME
awk - Manipulates text and matches patterns in files
SYNOPSIS
awk -f program [-Fcharacter][file ...]
awk [-Fcharacter] statement ... [file ...]
FLAGS
-Fcharacter
Uses character as the field separator character (a space by default).
-f program
Searches for the patterns and performs the actions found in the file program.
DESCRIPTION
The awk command provides a flexible text-manipulation language suitable for simple report gen-
eration. It is a more powerful tool for text manipulation than either sed or grep.
The awk command:
• Performs convenient numeric processing.
• Allows variables within actions.
• Allows general selection of patterns.
• Allows control flow in the actions.
• Does not require any compiling of programs.
Pattern-matching and action statements can be specified either on the command line or in a pro-
gram file. In either case, awk first reads all matching and action statements, then reads a line of
input and compares it to each specified pattern. If the line matches a specified pattern, awk per-
forms the specified actions and writes the result to standard output. When it has compared the
current input line to all patterns, it reads the next line.
The awk command reads input files in the order stated on the command line. If you specify a
filename as a - (dash) or do not specify a filename, awk reads standard input.
Enclose pattern-action statements on the command line in ’’ (single quotes) to protect them from
interpretation by the shell. Consecutive pattern-action statements on the same command line
must be separated by a ; (semicolon), within one set of quotes. Consecutive pattern-action state-
ments in an awk program file must appear on separate lines.
You can assign values to variables on the awk command line as follows:
variable=value
The awk command treats input lines as fields separated by spaces, tabs, or a field separator you
set with the FS variable. (Consecutive spaces are recognized as a single separator.) Fields are
referenced as $1, $2, and so on. $0 refers to the entire line.
527188-003 Hewlett-Packard Company 1−21