1.想取值機器的IP的值,技巧:一些字符用.*代替code
[root@cnsz142728 ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:50:56:9E:2F:38 inet addr:10.25.172.92 Bcast:10.25.173.255 Mask:255.255.254.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:334395 errors:0 dropped:0 overruns:0 frame:0 TX packets:156160 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:27189144 (25.9 MiB) TX bytes:9208757 (8.7 MiB) [root@cnsz142728 ~]# ifconfig eth0 |sed -n '2p' inet addr:10.25.172.92 Bcast:10.25.173.255 Mask:255.255.254.0 [root@cnsz142728 ~]# ifconfig eth0 |sed -n '2p' |sed 's#^.*dr##g' :10.25.172.92 Bcast:10.25.173.255 Mask:255.255.254.0 [root@cnsz142728 ~]# ifconfig eth0 |sed -n '2p' |sed 's#^.*dr##g'|sed 's# B.*##g' :10.25.172.92
2.方法二io
[root@cnsz142728 ~]# ifconfig eth0 |sed -n '2s#^.*dr##gp' :10.25.172.92 Bcast:10.25.173.255 Mask:255.255.254.0 [root@cnsz142728 ~]# ifconfig eth0 |sed -n '2s#^.*dr##gp'|sed 's# B.*##g' :10.25.172.92