Shell Primer-awk-2

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.