![](https://csdnimg.cn/release/download_crawler_static/9739716/bg3.jpg)
美河学习在线 www.eimhe.com
3
3
3
[root@liuhx ~]#
8.awk 增加表标题和行(主要用来统计)
[root@liuhx ~]# awk 'BEGIN{FS=":";print "name\tshell"}{print $1"\t"$7}END{print
"blue,/bin/bash"}' /etc/passwd
name shell
root /bin/bash
bin /sbin/nologin
daemon /sbin/nologin
adm /sbin/nologin
lp /sbin/nologin
sync /bin/sync
shutdown /sbin/shutdown
halt /sbin/halt
9.搜索哪一个关键字
[root@liuhx ~]# awk 'BEGIN{FS=":"}/root/' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@liuhx ~]#
10.搜索以什么开头的行
[root@liuhx ~]# awk '/^root/' /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@liuhx ~]#
11.搜索以多个开头的行
[root@liuhx ~]# awk '/^(sshd|root)/' /etc/passwd
root:x:0:0:root:/root:/bin/bash
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
[root@liuhx ~]#
12.搜索以字母开头的行
[root@liuhx ~]# awk '/^[rd]/' /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
[root@liuhx ~]#
13.条件判断
[root@liuhx ~]# awk 'BEGIN{FS=":"}{if($2=="x"&&$3<=10){print $0}}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin