直接来例子
$ 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 Nichols 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
说明:如果第5个字段大于4.5,就读入输入文件(datafile)的下一行,并从awk脚本的起点开始处理(即BEGIN块)。否则,打印第一个字段。
范例
$ awk '{if($2 ~ /S/){print ;exit 0}}' datafile southwest SW Chris Foster 2.7 .8 2 18 $ echo $? 0
说明:如果记录的第2个字段包含字母S,就打印该记录,并且从awk程序退出,退出状态则保存在变量$?中。