carlessanagustin
3/14/2016 - 9:42 AM

Get only the IP address

Get only the IP address

# method 1
$ echo $(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')

# method 2
$ echo $(ip -o -4 addr list eth0 | perl -n -e 'if (m{inet\s([\d\.]+)\/\d+\s}xms) { print $1 }')