[root@node1 awkdir]# cat awktxt4
adsf sdf sdf poi
lml woiu mn
ssdo llie sdf sdf saer po
lkj lkj power dsf sadf wer sadf
[root@node1 awkdir]# awk 'NF==4 {print $0}' awktxt4 #NF是内置变量,表示当前行的字段数量
adsf sdf sdf poi
使用一个简单的"条件":如果被处理的行正好有4列字段,那么被处理的行则满足"条件",满足条件的行会执行相应的动作,而动作就是{print $0},即打印当前行。也就是只打印满足条件的行,条件就是这一行文本有4列
[root@node1 awkdir]# awk 'NF>2 {print $0}' awktxt4
adsf sdf sdf poi
lml woiu mn
ssdo llie sdf sdf saer po
lkj lkj power dsf sadf wer sadf
[root@node1 awkdir]# awk 'NF<=4 {print $0}' awktxt4
adsf sdf sdf poi
lml woiu mn
[root@node1 awkdir]# awk '$1=="lml" {print $0}' awktxt4
lml woiu mn
原文链接:https://blog.csdn.net/wangzhicheng987/article/details/122825080 |