使用ifconfig取出网卡eth0的ip地址
方法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 ~]#
......
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<一天变一个样
转载于:https://blog.51cto.com/qizhong/1953680