if else:
awk '{if ($5>22) print $5 " bad ";else print $5 " ok"}' aa.txt
awk '{if ($5>100) {count++;print $5} else {count--; print $1}}' aa.txt
if 多重判断
df -h|awk '{if ($5>70) {count++;print ""} else if ($5>100) {count++;print "cc"} else { print "cc"}}'
df -h|grep -P "/$"|sed 's/%//'|awk '{if ($4>90) {count++;print "Error"} else if ($4>70) {count++;print "Warning"} else { print "Ok"}}'
将外部变量传入到 awk 中
将外部变量传入到awk + if 多重判断
SITE=$1
df -h|grep -P "/$"|sed 's/%//'|awk -v SITE=$SITE '{if ($4>90) {count++;printf SITE;print "Error"} else if ($4>70) {printf SITE;print
" Warning "} else { printf SITE;print " Ok "}}'
阅读(4026) | 评论(0) | 转发(0) |