MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
Here is the standard recursive factorial function:
function fact(num) {
if (num <= 1)
return 1
else
return num * fact(num - 1)
}
{ print $0 " factorial is " fact($0) }
The following program illustrates the use of getline with a pipe. Here, getline sets the
current record from the output of the wc command. The program prints the number of words
in each input file.
function words(file, string) {
string = "wc " fn
string | getline
close(string)
return ($2)
}
BEGIN {
for (i=1; i<ARGC; i++) {
fn = ARGV[i]
printf "There are %d words in %s.",
words(fn), fn
}
}
ENVIRONMENT VARIABLES
PATH
contains a list of directories that awk searches when looking for commands run by
system(expr), or input and output pipes.
Any other environment variable may be accessed by the awk program itself.
DIAGNOSTICS
Possible exit status values are:
0 Successful completion.
1 An error occurred.
When an awk program terminates because of a call to exit(), the exit status is the value
passed to exit().
1-36 Commands and Utilities