Awk control function, awk Function
Example
$ Cat datafile
Northwest 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 Nicholas 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} 'datafile
Northwest
Southwest
Southeast
Eastern
North
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} 'datafile
Southwest 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 $? .
References: http://www.linuxawk.com/jiaocheng/105.html