the method of taking the line of IP address in Linux system:
(1), ifconfig eth0 | grep "inet Addr"
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
Note: grep filters the contents of the string containing "inet addr"
(2), ifconfig eth0 | Sed-n ' 2p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
Note: sed-n ' 2p ' where-n parameter means "cancel default printing", 2p means "Print line 2nd"
(3), ifconfig eth0 | Sed-n '/inet addr/p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
(4), ifconfig eth0 | Sed-n '/bcast/p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
several ways to take IP addresses from Linux systems:
(1), ifconfig eth0 | grep "inet addr" | Awk-f ":" ' {print $} ' | awk ' {print '} '
10.57.36.112
(2), ifconfig eth0 | grep "inet addr" | Sed ' s#^.*addr:# #g ' | Sed ' s#. bc.*$# #g '
10.57.36.112
(3), ifconfig eth0 | grep "inet addr" | Cut-d:-f2| Cut-d ""-f1
10.57.36.112
(4), ifconfig eth0 | grep "inet addr" | Awk-f "[:]+" ' {Print $4} '
10.57.36.112
Note: The method which takes the line of IP address can use one of the above 4 methods, then filter, replace or intercept to obtain ip!
This article is from the "Bruce_tan" blog, make sure to keep this source http://380281.blog.51cto.com/370281/1758063
Several ways to take IP addresses from Linux systems