Linux 过滤本机IP地址
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:04:40:3F
inet addr:192.168.168.100 Bcast:192.168.168.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe04:403f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7886 errors:0 dropped:0 overruns:0 frame:0
TX packets:4376 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:706997 (690.4 KiB) TX bytes:701464 (685.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:220 errors:0 dropped:0 overruns:0 frame:0
TX packets:220 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17328 (16.9 KiB) TX bytes:17328 (16.9 KiB)
需要使用sed和awk实现
[root@localhost ~]# ifconfig | sed -n 2p|awk -F “inet addr:” ‘{print $2}’|awk -F " " ‘{print $1}’
192.168.168.100