[root@xusx xusx]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:9A:CD:B1
inet addr:192.168.138.138 Bcast:192.168.138.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9a:cdb1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:68094 errors:0 dropped:0 overruns:0 frame:0
TX packets:41042 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28601665 (27.2 MiB) TX bytes:5618664 (5.3 MiB)
第一种
[root@xusx ~]# ifconfig eth0|awk -F "[: ]+" 'NR==2{print $4}'
192.168.138.138
第二种
[root@xusx ~]# ifconfig eth0|sed -n '2p'|sed -r 's#(^.*r:)|(Bc.*$)##g'
192.168.138.138
[root@xusx ~]# ifconfig eth0|sed -nr '2s#^.*r:| Bc.*$##gp'
192.168.138.138
第三种
[root@xusx ~]# ifconfig eth0|egrep -o "inet addr:[0-9.]*"
inet addr:192.168.138.138
[root@xusx ~]# ifconfig eth0|egrep -o "inet addr:[0-9.]*"|egrep -o "[0-9.]*"
192.168.138.138
第四种
[root@xusx ~]# ifconfig eth0 |awk 'NR==2'
inet addr:192.168.138.136 Bcast:192.168.138.255 Mask:255.255.255.0
[root@xusx ~]# ifconfig eth0 |awk 'NR==2'|cut -d ":" -f2
192.168.138.136 Bcast
[root@xusx ~]# ifconfig eth0 |awk 'NR==2'|cut -d ":" -f2|cut -d " " -f1
192.168.138.136