Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (m - o) nawk(1)
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:
nawk ’length >72’ chapter1
This command selects each line of the file chapter1 that is longer than 72 bytes. nawk
then writes these lines to standard output because no action is specified.
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 file (chapter1), enter:
nawk -f sum2.awk chapter1
4. To print the first two fields of a file named filename in reverse order, enter:
nawk ’{ print $2, $1 }’filename
5. The following nawk 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: awk(1), grep(1), sed(1).
Functions: printf(3).
Files: locale(4).
527188-007 Hewlett-Packard Company 6−35