Awk control functions
Example
$ Cat datafilenorthwest NW Joel Craig 3.0. 98 3 4 western WE Sharon Kelly 5.3. 97 5 23 southwest SW Chris Foster 2.7. 8 2 18 southern SO May Chin 5.1. 95 4 15 southeast SE Derek Johnson 4.0. 7 4 17 eastern EA Suan Beal 4.4. 84 5 20 northeast ne tj nickls 5.1. 94 3 13 north NO Val Shultz 4.5. 89 5 9 central CT Sheri Watson 5.7. 94 5 13 $ awk '{if ($5 >= 4.5) next; print $1} 'datafilenorthwestsouthwestsoutheasteasternnorth
Note: If the number of fields is greater than 5th, read the next line of the input file (datafile) and start from the starting point of the awk script (that is, the BEGIN block ). Otherwise, print the first field.
Example
$ Awk '{if ($2 ~ /S/) {print; exit 0} 'datafilesouthwest SW Chris Foster 2.7. 8 2 18 $ echo $? 0
Note: If the first field of the record contains the letter S, the record is printed and exited from the awk program. The exit state is saved in the variable $? .