语法:
一、if (条件){语句}[else 语句] 单分支
二、if (条件){语句}else if( 条件){语句} 多分支
示例:
1、[root@localhost ~]# awk -F: '{if($3>=1000)print $1,$3}' /etc/passwd zjz 1000 zjz1 1001
2、[root@localhost ~]# awk -F: '{if($NF=="/bin/bash")print $1}' /etc/passwd root zjz zjz1
3、[root@localhost ~]# awk -F: '{if($3>=1000){print "Common user:%s ",$1}else {print "root or Sysuser:%s ",$1}}' /etc/passwd root or Sysuser:%s sshd root or Sysuser:%s apache Common user:%s zjz Common user:%s zjz1 4、[root@localhost ~]# df -hT |awk -F% '/^/dev/sda1/{print $1}'|awk '$NF>=10{print $1,$6}' /dev/sda1 13 5、[root@localhost ~]# awk 'BEGIN{test=20;if(test>90){print "very good"}else if (test>60){print "good"}else {print "no pass"} }' no pass