正则表达式练习
ifconfig eth0 | sed -n '2p'| awk '{print $2}' | awk -F: '{print $2}'
ifconfig eth0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1
ifconfig eth0 | sed -n '2p'| awk -F "[: ]+" '{print $4}' # +重复前面多个分隔符 [空格,冒号为分隔符]
ifconfig eth0 | awk -F "[: ]+" 'NR==2 {print $4}'
[root@augustyang 123]# sed 's#\(ddd\) \(kkk\)##g' test.txt
[root@augustyang 123]# sed 's#\(ddd\) \(kkk\)#\1#g' test.txt
ddd
[root@augustyang 123]# sed 's#\(ddd\) \(kkk\)#\1 \2#g' test.txt
ddd kkk
[root@augustyang 123]# stat /etc | sed -n '4p'| awk -F"[(/]" '{print $2}'
0755
[root@augustyang 123]# stat /etc | awk -F "[(/]" ' NR ==4 {print $2}'
0755
posted on 2016-11-09 23:00 augustyang 阅读(356) 评论(0) 编辑 收藏 举报