Go to the previous, next section.
Useful awk
programs are often short, just a line or two. Here is a
collection of useful, short programs to get you started. Some of these
programs contain constructs that haven't been covered yet. The description
of the program will give you a good idea of what is going on, but please
read the rest of the manual to become an awk
expert!
awk '{ num_fields = num_fields + NF }
END { print num_fields }'
awk 'length($0) > 80'
awk 'NF > 0'
awk '{ if (NF > 0) print }'
awk 'BEGIN { for (i = 1; i <= 7; i++)
print int(101 * rand()) }'
ls -l files | awk '{ x += $4 } ; END { print "total bytes: " x }'
expand file | awk '{ if (x < length()) x = length() }
END { print "maximum line length is " x }'
expand
program to change tabs into spaces,
so the widths compared are actually the right-margin columns.
Go to the previous, next section.