A colleague's friend is taking part in the written examination, encountered such a problem let him help solve, the result colleague found me to help him to fix. Really feeling: communication developed in some ways, I really do not know is not good ah! The topic is as follows, generally we use ifconfig to view the network card information, what command can you pass, let it only output IP address 192.168.42.128
Seemingly simple problems, and implementation is not too simple. Look at the following ideas.
[Email protected] ~]# ifconfig eth0
inet addr:192.168.42.128 bcast:192.168.42.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FE9E:700E/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:135 errors:0 dropped:0 overruns:0 frame:0
TX packets:216 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:14062 (13.7 KiB) TX bytes:26007 (25.3 KiB)
[Email protected] ~]# ifconfig eth0 | grep "inet Addr"
inet addr:192.168.42.128 bcast:192.168.42.255 mask:255.255.255.0
This is a very simple step, and then it needs to be done with awk, as shown below, to solve this problem.
[Email protected] ~]# ifconfig eth0 | grep "inet addr" | awk ' {print $} '
addr:192.168.42.128
[Email protected] ~]# ifconfig eth0 | grep "inet addr" | awk ' {print $} ' | Awk-f: ' {print $} '
192.168.42.128
"Go" Linux How to get IP address by command only