通过sed命令获取IP地址

ifconfig wlan0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g'

整个操作过程如下:

[root@localhost bak]# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr A0:88:B4:34:26:C0  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a288:b4ff:fe34:26c0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:42138 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11431 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:61583676 (58.7 MiB)  TX bytes:1193275 (1.1 MiB)

[root@localhost bak]# ifconfig wlan0 | grep 'inet addr'
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
[root@localhost bak]# ifconfig wlan0 | grep 'inet addr' | sed 's/^.*addr://g'
192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
[root@localhost bak]# ifconfig wlan0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g'
192.168.1.111  
[root@localhost bak]#

你可能感兴趣的:(linux,通过sed命令获取IP地址,sed,ifconfig,linux获取IP地址)