实例1:
[root@localhost ~]# cat items-sold.txt 101 2 10 5 8 10 12 102 0 1 4 3 0 2 103 10 6 11 20 5 13 104 2 3 4 0 6 5 105 10 2 5 7 12 6 [root@localhost ~]# cat so { i=2;total=0; while(i++<=NF) if($i==0) { #某月份销量为0则退出脚本 print "Item",$1,"had a month with no item sold"; exit; } } [root@localhost ~]# awk -f so items-sold.txt Item 102 had a month with no item sold 七、next语句next提前结束本行处理,进入下一行处理。
实例1:
[root@localhost ~]# cat next.txt
aa bb
cc dd
ee ff
gg hh
[root@localhost ~]# awk '{if(NR == 1) next;print $1,$2}' next.txt
cc dd
ee ff
gg hh