小方法——匹配ip地址
[root@MiWiFi-R1CM-srv ~]# ifconfig |sed -n '2p' inet addr:192.168.139.128 Bcast:192.168.139.255 Mask:255.255.255.0 [root@MiWiFi-R1CM-srv ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:30:61:2E inet addr:192.168.139.128 Bcast:192.168.139.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe30:612e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:493 errors:0 dropped:0 overruns:0 frame:0 TX packets:79 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:52802 (51.5 KiB) TX bytes:14608 (14.2 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:30:61:38 inet addr:192.168.31.66 Bcast:192.168.31.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe30:6138/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:639734 errors:0 dropped:0 overruns:0 frame:0 TX packets:306759 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:216599719 (206.5 MiB) TX bytes:32159081 (30.6 MiB) 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:226 errors:0 dropped:0 overruns:0 frame:0 TX packets:226 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:167792 (163.8 KiB) TX bytes:167792 (163.8 KiB) [root@MiWiFi-R1CM-srv ~]# ifconfig |sed -n '2p' | sed -r 's#.*r:(.*) B.*k:(.*)#\1 \2#g' 192.168.139.128 255.255.255.0
[root@MiWiFi-R1CM-srv ~]# ifconfig | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' 192.168.139.128 192.168.139.255 255.255.255.0 192.168.31.66 192.168.31.255 255.255.255.0 127.0.0.1 255.0.0.0
[root@MiWiFi-R1CM-srv ~]# ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' 192.168.139.128 192.168.139.255 255.255.255.0 192.168.31.66 192.168.31.255 255.255.255.0 127.0.0.1 255.0.0.0
[root@MiWiFi-R1CM-srv ~]# ifconfig |egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" 192.168.139.128 192.168.139.255 255.255.255.0 192.168.31.66 192.168.31.255 255.255.255.0 127.0.0.1 255.0.0.0