MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
The next program interchanges the first and second fields of input lines:
{
tmp=$1
$1=$2
$2 = tmp
print
}
The following inserts line numbers so that output lines are left-aligned:
{printf "%–6d: %s\n", NR, $0}
The following prints input records in reverse order (assuming sufficient memory):
{
a[NR] = $0 # index using record number
}
END {
for (i = NR; i>0; --i)
print a[i]
}
The next program determines the number of lines starting with the same first field:
{
++a[$1] # array indexed using the first field
}
END { # note output will be in undefined order
for (i in a)
print a[i], "lines start with", i
}
Commands and Utilities 1-33