使用命令: awk ,sed
注意: 要注意! 正则有使用规则的!
先看 ip 地址, 使用命令:
ifconfig eth0 |awk 'NR==2' / ifonfig eth0 |sed -n '2p'
输出结果: 省略一下, 可以自己去试一下.
- ifconfig eth0 |awk 'NR==2' -F "[: ]+" '{print$4}'
- ifconfig eth0 |sed -nr '2s#^.(.) Bc.$#\1#gp'
难点在于要理解正则和三剑客配合使用的原因.
需要多多在 xshell 上练习!
来源: http://www.bubuko.com/infodetail-3034999.html