使用ifconfig取出网卡eth0ip地址

方法1sed

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr'2s#.*dr:|Bca.*##gp'

10.0.0.200 

[root@ZHOUQIZHONG ~]#

方法2sed

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr'2s#.*dr:(.*)Bca.*#\1#gp'

10.0.0.200 

[root@ZHOUQIZHONG ~]#

方法3sed+cut

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -n'2p'|cut -d ':' -f2 |cut -d ' ' -f1

10.0.0.200

[root@ZHOUQIZHONG ~]#

方法4awk

[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F '[: ]+''NR==2{print $4}'

10.0.0.200

[root@ZHOUQIZHONG ~]#

方法5awk

[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F'addr:|Bcast:' 'NR==2{print $2}'

10.0.0.200 

[root@ZHOUQIZHONG ~]#

......

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<一天变一个样