这三个”剑客”的特长。
grep 更适合单纯的查找或匹配文本
sed 更适合编辑匹配到的文本
awk 更适合格式化文本,对文本进行较复杂格式处理
http://www.zsythink.net/archives/1336
awk ‘{print $0}’
[root@n9e ~]# awk '{print $0}' /etc/resolv.conf
# Generated by NetworkManager
options rotate
domain boccfc.com
search test.boccfc.com boccfc.com
nameserver 10.182.211.82
nameserver 10.182.211.83
nameserver 114.114.114.114
nameserver 1.1.1.1
nameserver 8.8.8.8
[root@n9e ~]# awk '{print $1}' /etc/resolv.conf
#
options
domain
search
nameserver
nameserver
nameserver
nameserver
nameserver
[root@n9e ~]# awk '{print $2}' /etc/resolv.conf
Generated
rotate
boccfc.com
test.boccfc.com
10.182.211.82
10.182.211.83
114.114.114.114
1.1.1.1
8.8.8.8
[root@n9e ~]#
[root@n9e ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 48G 4.6G 43G 10% /
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 9.0M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 xfs 1.1G 150M 914M 15% /boot
tmpfs tmpfs 396M 0 396M 0% /run/user/700
[root@n9e ~]# df -TH | awk '{print $5}'
Avail
43G
2.0G
2.0G
2.0G
2.0G
914M
396M
[root@n9e ~]#
[chroot@n9e ~]$ awk -F":" '{ print $1 }' /etc/passwd |head
root
bin
daemon
adm
lp
sync
shutdown
halt
operator
[chroot@n9e ~]$