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

nawk(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:
nawk length >72 chapter1
This command selects each line of the le chapter1 that is longer than 72 bytes. nawk
then writes these lines to standard output because no action is specied.
2. To display all lines between the words start and stop,enter:
nawk /start/,/stop/ chapter1
3. To run a nawk program (sum2.awk) that processes a le (chapter1), enter:
nawk -f sum2.awk chapter1
4. To print the rst two elds of a le named lename in reverse order, enter:
nawk { print $2, $1 }’filename
5. The following nawk 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: awk(1), grep(1), sed(1).
Functions: printf(3).
Files: locale(4).
634 Hewlett-Packard Company 527188-003