awk -F ‘:’ ‘{print $1}’ test.txt
将test.txt中第1段打印出来
awk ‘{print $0}’ test.txt
将test.txt中所有段打印出来
awk -F ‘:’ ‘{print $1,$2,$3}’ test.txt
将test.txt中第1,2,3段打印出来
awk -F ‘:’ ‘{print $1"#"$2"#"$3}’ test.txt
将test.txt中第1,2,3段以#号隔开并打印出来
[root@allen awk]# awk ‘/oo/’ test.txt
root❌0:0:root:/root:/bin/bash
lp❌4:7:lp:/var/spool/lpd:/sbin/nologin
mail❌8:12:mail:/var/spool/mail:/sbin/nologin
operator❌11:0:operator:/root:/sbin/nologin
postfix❌89:89::/var/spool/postfix:/sbin/nologin
匹配,将test.txt文档中含有oo字符段打印出来
[root@allen awk]#awk -F ‘:’ ‘$1 ~ /oo/’ test.txt
root❌0:0:root:/root:/bin/bash
将第一段含有oo字符段打印出来
awk -F ‘:’ ‘$1 ~ /o+/’ test.txt
将文档中含有oo字符段全部打印出来
awk -F ‘:’ ‘/root|user/ {print $0}’ text.txt
将 text文档中含有root user字符段全部打印出来
awk -F ‘:’ ‘$3==0’ test.txt
第三段等于0
awk -F ‘:’ ‘$3>=1000 {print $1}’ test.txt
第三段大于等于1000
awk -F ‘:’ ‘$7!="/sbin/nologin" {print $0}’ text.txt
第七段不属于/sbin/nologin
[root@allen awk]# awk -F ‘:’ ‘$3<$4’ text.txt
adm❌3:4:adm:/var/adm:/sbin/nologin
lp❌4:7:lp:/var/spool/lpd:/sbin/nologin
mail❌8:12:mail:/var/spool/mail:/sbin/nologin
games❌12