第三周作業(yè):sed練習(xí)
1、用sed取出df -h顯示出的/dev開頭的已用磁盤的數(shù)據(jù)端铛,帶單位泣矛。
如 紅框內(nèi)容為所提取數(shù)據(jù)
QQ圖片20210406224158.jpg
[root@centos8 ~]# df -h | sed -nr '/^\/dev\/sd/s#.*([ ]+[0-9.]+[GM])([ ]+[0-9.]+[GM]).*#\1#p'
1.5G
33M
132M
[root@centos8 ~]# df -h |sed -nr '/^\/dev/{s#(\S+)(\s+)([0-9.]+[GM][ ]+)([0-9.]+[GM])(.*)#\4#p}'
1.5G
33M
132M
2疲眷、用sed取出free -h 剩余空間內(nèi)容禾蚕,不帶單位(假定單位都是Gi)
如下圖紅框中的內(nèi)容 為 所提取的內(nèi)容
QQ圖片20210406224235.jpg
[root@centos8 ~]# free -h |awk -F" " '/^.*:/{print $4}'|sed -nr 's/([0-9.]+).*/\1/p'
726
2.0
[root@centos8 ~]# free -h |sed -nr '/^.*:/{s#(\S+)(\s+)(([0-9.]+)(\w+\s+){2})([0-9.]+)(.*)#\6#p}'
726
2.0
[root@centos8 ~]# free -h | sed -nr 's#(\S+)(\s+)(([0-9.]+)(\w+\s+){2})([0-9.]+)(.*)#\6#p'
726
2.0