MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
If you add |expr to a print or printf statement, awk treats the string value of expr as an
executable command and runs it with the output from the statement piped as input into the
command.
As mentioned earlier, you can have only a limited number of files and pipes open at any time.
To avoid going over the limit, use the close function to close files and pipes when you no
longer need them.
print and printf are also available as functions with the same calling sequence, but no
redirection.
EXAMPLES
awk ’{print NR ":" $0}’ input1
outputs the contents of the file input1 with line numbers prepended to each line.
The following is an example using var=value on the command line.
awk ’{print NR SEP $0}’ SEP=":" input1
awk can also read the program script from a file as in the command line:
awk -f addline.awk input1
which produces the same output when the file addline.awk contains
{print NR ":" $0}
The following program appends all input lines starting with January to the file jan (which
may or may not exist already), and all lines starting with February or March to the file
febmar:
/ˆJanuary/ {print >> "jan"}
/ˆFebruary|ˆMarch/ {print >> "febmar"}
This program prints the total and average for the last column of each input line:
{s += $NF}
END {print "sum is", s, "average is", s/NR}
1-32 Commands and Utilities