方法1:sed
[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr‘2s#.*dr:|Bca.*##gp‘
10.0.0.200
[root@ZHOUQIZHONG ~]#
方法2:sed
[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr‘2s#.*dr:(.*)Bca.*#\1#gp‘
10.0.0.200
[root@ZHOUQIZHONG ~]#
方法3:sed+cut
[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -n‘2p‘|cut -d ‘:‘ -f2 |cut -d ‘ ‘ -f1
10.0.0.200
[root@ZHOUQIZHONG ~]#
方法4:awk
[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F ‘[: ]+‘‘NR==2{print $4}‘
10.0.0.200
[root@ZHOUQIZHONG ~]#
方法5:awk
[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F‘addr:|Bcast:‘ ‘NR==2{print $2}‘
10.0.0.200
[root@ZHOUQIZHONG ~]#
......
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<一天变一个样
本文出自 “qizhong” 博客,请务必保留此出处http://qizhong.blog.51cto.com/12933988/1953680
原文地址:http://qizhong.blog.51cto.com/12933988/1953680