擷取ip

wang_0720發表於2013-11-06
方法一
[root@192 andy]# ifconfig eth0|grep -w inet|cut -d " " -f 12|cut -d ":" -f 2
192.168.151.141
方法二
[root@192 andy]# ifconfig eth0|grep -w inet|cut -c 21-35
192.168.151.141
方法三
[root@192 andy]# ifconfig eth0|grep -w "inet" |cut -d " " -f 12|sed 's/^.*://g'
192.168.151.141
方法四
[root@192 andy]# ifconfig eth0|grep -w "inet" |cut -d " " -f 12|awk -F ":" '{print $2}'
192.168.151.141
方法五
[root@192 andy]# ifconfig eth0|grep -w "inet" |sed -e 's/^.*addr://g ; s/Bcast.*$//g'
192.168.151.141

[root@192 andy]# ifconfig eth0|grep -w "inet" |sed -e 's/^.*addr://g' 
-e 's/Bcast.*$//g'
192.168.151.141
方法六
[root@192 andy]# ifconfig eth0|grep -w inet|awk -F ":" '{print $2}'|awk  '{print $1}'
192.168.151.141
方法七
[root@192 andy]# ifconfig eth0|grep inet|awk -F "[ :]" '{print $13}'
192.168.151.141
方法八
[root@192 andy]# ifconfig eth0|awk -F "[ :]+" 'NR==2{print $4}'
192.168.151.141

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775810/,如需轉載,請註明出處,否則將追究法律責任。

相關文章