Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)

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 le longer than 72 bytes, enter:
awk length >72 chapter1
This command selects each line of the le chapter1 that is longer than 72 bytes. awk
then writes these lines to standard output because no action is specied.
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 le (chapter1), enter:
awk -f sum2.awk chapter1
4. To print the rst two elds of a le named lename in reverse order, enter:
awk { print $2, $1 }’filename
5. The following awk program prints the rst two elds of the input le in reverse order,
with input elds separated by a comma and a space, then adds up the rst 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).
126 Hewlett-Packard Company 527188-004