# echo "hello bob" | awk '{ print $2 }'

bob


Awk can do a lot more than most people ask of it. The basic three-part

structure of an awk program is something like this:


awk '


BEGIN {

Any kind of setup, variable initialization, whatever you need

to do before processing awk's input goes here. Maybe you want

awk to produce some stdout without any stdin at all, code

for that can go here.

}

{

Awk gets it's input from stdin. By default awk sees its input as

records, each record is a string of zero or more characters followed

by a newline. Each record passes through here, and the code

here is applied to each record. Awk can produce output from

any of its three sections, and the output goes to stdout.

}


END {

After all the input records have been processed, code

can run here if needed.

}'


# echo hello | awk ''

# echo hello > /dev/null


In both of the above examples, hello goes to the same place that lost socks go.


The GNU Awk User's Guide is probably the definitive awk documentation.