The conditional operator of awk
Shows the first line with root
[[email protected] ~]# awk-f ': ' $1== ' root ' 1.txt
Root:x:0:0:root:/root:/bin/bash
Show first line with root print first paragraph
[[email protected] ~]# awk-f ': ' $1== ' root ' {print '} ' 1.txt
Root
The first paragraph equals root or the seventh paragraph equals nologin.
[[email protected] ~]# awk-f ': ' $1== ' root | | $7~/nologin/' 1.txt
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Adm:x:3:4:adm:/var/adm:/sbin/nologin
.....
The third paragraph is greater than or equal to 500
[Email protected] ~]# awk-f ': ' $3>=500 ' 1.txt
Wangshaojun:x:500:500::/home/wangshaojun:/bin/bash
Shaojun:x:501:501::/home/shaojun:/bin/bash
Aming:x:502:502::/home/aming:/bin/bash
The seventh paragraph is not equal to/sbin/nologin
[Email protected] ~]# awk-f ': ' $7!= '/sbin/nologin ' 1.txt
[Email protected] ~]# awk-f ': ' $7!~/nologin/' 1.txt
Root:x:0:0:root:/root:/bin/bash
Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Wangshaojun:x:500:500::/home/wangshaojun:/bin/bash
Shaojun:x:501:501::/home/shaojun:/bin/bash
Aming:x:502:502::/home/aming:/bin/bash
The third paragraph is less than the fourth paragraph of the line
[Email protected] ~]# awk-f ': ' $3<$4 ' 1.txt
Adm:x:3:4:adm:/var/adm:/sbin/nologin
Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
Mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
Uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
Games:x:12:100:games:/usr/games:/sbin/nologin
......
The third paragraph equals the fourth paragraph of the row
[Email protected] ~]# awk-f ': ' $3==$4 ' 1.txt
Root:x:0:0:root:/root:/bin/bash
Bin:x:1:1:bin:/bin:/sbin/nologin
Daemon:x:2:2:daemon:/sbin:/sbin/nologin
Nobody:x:99:99:nobody:/:/sbin/nologin
....
////////////////////////////////////////////////////////////////////////////////////
Summary: = = < >! =
Shell Primer-awk-2