这三个”剑客”的特长。
    grep 更适合单纯的查找或匹配文本
    sed 更适合编辑匹配到的文本
    awk 更适合格式化文本,对文本进行较复杂格式处理

    http://www.zsythink.net/archives/1336

    awk ‘{print $0}’

    1. [root@n9e ~]# awk '{print $0}' /etc/resolv.conf
    2. # Generated by NetworkManager
    3. options rotate
    4. domain boccfc.com
    5. search test.boccfc.com boccfc.com
    6. nameserver 10.182.211.82
    7. nameserver 10.182.211.83
    8. nameserver 114.114.114.114
    9. nameserver 1.1.1.1
    10. nameserver 8.8.8.8
    11. [root@n9e ~]# awk '{print $1}' /etc/resolv.conf
    12. #
    13. options
    14. domain
    15. search
    16. nameserver
    17. nameserver
    18. nameserver
    19. nameserver
    20. nameserver
    21. [root@n9e ~]# awk '{print $2}' /etc/resolv.conf
    22. Generated
    23. rotate
    24. boccfc.com
    25. test.boccfc.com
    26. 10.182.211.82
    27. 10.182.211.83
    28. 114.114.114.114
    29. 1.1.1.1
    30. 8.8.8.8
    31. [root@n9e ~]#
    1. [root@n9e ~]# df -TH
    2. Filesystem Type Size Used Avail Use% Mounted on
    3. /dev/mapper/centos-root xfs 48G 4.6G 43G 10% /
    4. devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
    5. tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
    6. tmpfs tmpfs 2.0G 9.0M 2.0G 1% /run
    7. tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
    8. /dev/sda1 xfs 1.1G 150M 914M 15% /boot
    9. tmpfs tmpfs 396M 0 396M 0% /run/user/700
    10. [root@n9e ~]# df -TH | awk '{print $5}'
    11. Avail
    12. 43G
    13. 2.0G
    14. 2.0G
    15. 2.0G
    16. 2.0G
    17. 914M
    18. 396M
    19. [root@n9e ~]#
    1. [chroot@n9e ~]$ awk -F":" '{ print $1 }' /etc/passwd |head
    2. root
    3. bin
    4. daemon
    5. adm
    6. lp
    7. sync
    8. shutdown
    9. halt
    10. mail
    11. operator
    12. [chroot@n9e ~]$