Linux正则表达式结合三剑客实例

Linux正则表达式结合三剑客实例

案例一:
取 ifconfig eth0 中的 inet addr 的 ip
法一:ifconfig eth0|sed -n '2p'|sed -n 's#^.dr:##gp'|sed -n 's# B.$##gp'
Linux正则表达式结合三剑客实例
法二:ifconfig eth0|sed -n'2s#^.dr:##gp'|sed -n 's# B.$##gp'
Linux正则表达式结合三剑客实例
法三(后向引用):ifconfig eth0|sed -nr '2s#^.dr:(.) B.*$#\1#gp'
Linux正则表达式结合三剑客实例
练习法三:需要注意 sed: -e expression #1, char 25: Unmatched ( or ( 表示需要转义
Linux正则表达式结合三剑客实例

猜你喜欢

转载自blog.51cto.com/12384628/2116009