For many Linux beginners, there are many basic interview, you may encounter the need to extract the IP address of the problem, below I summed up a number of methods to take IP addresses, I hope you can learn the knowledge
For example, I need to extract the IP address of the eth0
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/8E/B8/wKiom1jKBqWg379mAAIYs9xX4mg747.png-wh_500x0-wm_ 3-wmp_4-s_1863807413.png "title=" Qq20170316112838.png "alt=" Wkiom1jkbqwg379maaiys9xx4mg747.png-wh_50 "/>
Method One: Use awk to implement
Ifconfig eth0 |grep "inet addr" |awk ' {print $} ' | Awk-f: ' {print $} '
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8E/B8/wKiom1jKB5KQeKOVAAESnlzNMdY414.png-wh_500x0-wm_ 3-wmp_4-s_3467466508.png "title=" Qq20170316113332.png "alt=" Wkiom1jkb5kqekovaaesnlznmdy414.png-wh_50 "/>
Parameter description:
awk defaults to spaces as separators
-F Specify delimiter
' {print $} ' outputs a second parameter
Method Two: Use SED to implement
[Email protected] ~]# ifconfig eth0 |sed-rn ' S#^.*DR: (. *) BC.*$#\1#GP '
192.168.10.18
The most common is the above two methods, if there are other methods, will be updated up
This article is from the "Lonely No Color" blog, please be sure to keep this source http://tenderness.blog.51cto.com/8855468/1907196
Multiple ways to take IP addresses from Linux