Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
awk(1) OSS Shell and Utilities Reference Manual
There are no explicit conversions between numbers and strings. To force an expression to be
treated as a number, add 0 (zero) to it. To force it to be treated as a string, append a null string
("").
EXAMPLES
1. To display the lines of a file longer than 72 bytes, enter:
awk ’length >72’ chapter1
This command selects each line of the file chapter1 that is longer than 72 bytes. awk
then writes these lines to standard output because no action is specified.
2. To display all lines between the words start and stop,enter:
awk ’/start/,/stop/’ chapter1
3. To run an awk program (sum2.awk) that processes a file (chapter1), enter:
awk -f sum2.awk chapter1
4. To print the first two fields of a file named filename in reverse order, enter:
awk ’{ print $2, $1 }’filename
5. The following awk program prints the first two fields of the input file in reverse order,
with input fields separated by a comma and a space, then adds up the first column and
prints the sum and average:
BEGIN { FS = ",[ ]*|[ ]+" }
{ print $2, $1}
{ s += $1 }
END { print "sum is", s, "average is", s/NR }
RELATED INFORMATION
Commands: grep(1), nawk(1), sed(1).
Functions: printf(3).
Files: locale(4).
1−26 Hewlett-Packard Company 527188-003