方法一:
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|sed 's#^.*addr:##g'|sed 's#Bc.*$##g'
10.0.0.201
方法二:
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|sed 's#^.*addr:\(.*\)Bc.*$#\1#g'
10.0.0.201
方法三:(推荐)
[root@congzhongzhi~]# ifconfig eth0|sed -nr'2s#^.*addr:(.*) Bca.*$#\1#g'p
10.0.0.201
方法四:
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|sed -r 's#(^.*addr:)(.*)(Bc.*$)#\2#g'
10.0.0.201
方法五:
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|egrep -o "([0-9]{1,3}.?){4} "|head -1
10.0.0.201
方法六:(推荐)
[root@congzhongzhi~]# ifconfig eth0 |awk -F "[ :]+" 'NR==2{print $4}'
10.0.0.201
方法七:(推荐)
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|sed 's#:# #g'|awk '{print $3}'
10.0.0.201
方法八:awk在默认的情况下,会自动忽略前面的空格
[root@congzhongzhi~]# ifconfig eth0|sed -n '2p'|sed 's#:##g'|awk '{print $2}'|sed 's#addr##g'
10.0.0.201
方法九:
[root@congzhongzhi~]# ifconfig eth0|awk 'NR==2'|cut -c 21-30
10.0.0.201
方法十:
[root@congzhongzhi~]# ifconfig eth0 |grep "inet addr"|cut -d ":" -f2|tr "Bcast" " "
10.0.0.201
方法十一:
[root@congzhongzhi~]# ifconfig eth0|grep "inet addr"|awk -F "[ :]+" '{print$4}'
10.0.0.201
转载于:https://blog.51cto.com/congzz/1953311