awk高级应用(条件控制语句,循环语句)

awk判断根分区磁盘使用量:::

df / |grep / |awk '{if($4<15000000)print "根分区磁盘可用量低于15G了";else print "磁盘可用量还行"}'

awk判断/boot分区磁盘使用量:::

[root@localhost ~]# df |grep /boot| awk '{if($4<140000)print "false";else print "ok"}'
ok

[root@localhost ~]# df |grep /boot| awk '{if($4<900000)print "false";else print "ok"}'

false

 以下逻辑才是对的,上面的截图逻辑是错的

 

 

awk在输出内容前面和结尾添加提示语: 点缀开始和最后

awk 'BEGIN{printf "this is system administrator\n"} {print $1}END{printf "the game over\n"}' test.txt

 

posted @ 2023-07-17 10:32  往事已成昨天  阅读(19)  评论(0编辑  收藏  举报