MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
As the following program reads in each line of input, it reports whether the line matches a pre-
determined value:
function randint() {
return (int((rand()+1)*10))
}
BEGIN {
prize[randint(),randint()] = "$100";
prize[randint(),randint()] = "$10";
prize[1,1] = "the booby prize"
}
{
if (($1,$2) in prize)
printf "You have won %s!\n", prize[$1,$2]
}
The following example prints lines, the first and last fields of which are the same, reversing
the order of the fields:
$1= =$NF {
for(i=NF;i>0;--i)
printf "%s", $i (i>1 ? OFS : ORS)
}
The following program prints the input files from the command line. The infiles function
first empties the passed array, and then fills the array. Notice that the extra parameter i of
infiles is a local variable.
function infiles(f,i) {
for (i in f)
delete f[i]
for (i = 1; i < ARGC; i++)
if (index(ARGV[i],"=") = = 0)
f[i] = ARGV[i]
}
BEGIN {
infiles(a)
for (i in a)
print a[i]
exit
}
Commands and Utilities 1-35