AWK Variables
awk variables are initialized to either zero or the empty string the first time they are used. Which one depends on how they are used, of course.
Variables are also useful for keeping intermediate values. This example also introduces the use of semicolons for separating statements:
$ awk '{d=($2-($1-4));s=($2+$1);print d/sqrt(s),d*d/s }' filename
Note that the final statement, a "print" in this case, does not need a semicolon. It doesn't hurt to put it in, though.
Integer variables can be used to refer to fields. If one field contains information about which other field is important, this script will print only the important field:
$ awk '{imp=$1; print $imp }' filename
The special variable NF tells you how many fields are in this record. This script prints the first and last field from each record, regardless of how many fields there are:
$ awk '{print $1,$NF }' filename