[root@YZC ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:0C:29:86:02:03 inet addr:59.151.110.2 Bcast:59.151.110.255 Mask:255.255.255.0 #->IP:59.151.110.2是我們要單獨提取出來的; inet6 addr: fe80::20c:29ff:fe86:203/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2600 errors:0 dropped:0 overruns:0 frame:0 TX packets:921 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:238456 (232.8 KiB) TX bytes:96528 (94.2 KiB) Interrupt:59 Base address:0x2000 [root@YZC ~]# ifconfig eth0 | grep Bcast #->以"Bcast"爲關鍵字,將IP所在行給過濾出來; inet addr:59.151.110.2 Bcast:59.151.110.255 Mask:255.255.255.0 [root@YZC ~]# ifconfig eth0 | grep Bcast | awk -F: '{print $2}' #->過濾出來之後我們運用awk命令再進行操作; #->-F: '{print $2}' 表示以":"爲分隔符,並打印出第二個字段的內容 59.151.110.2 Bcast [root@YZC ~]# ifconfig eth0 | grep Bcast | awk -F: '{print $2}' | awk -F " " '{print $1}' #->再次將以上的字段通過awk命令進行截取; 59.151.110.2 ~