extracting the ip address from ifconfig

Hi
I am trying to create a script extracting the IP provided by ifconfig.
I tried with grep + awk but I am returned more than I need.

  
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' 

and returns

 
addr:10.15.1.64

How can I remove "addr:" string?
Thanks in advance

awk can grep, no UUOC required.
Please post the output of

/sbin/ifconfig eth0
A bit modification : 

/sbin/ifconfig eth0 | awk -F":" '/inet addr:/ { print $2 }' 
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | cut -d":" -f2

or

/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | awf -F":" '{print $2}'

:slight_smile:

Depending ifconfig's o/p this should also work:

ifconfig eth0 | awk -F":| +" '/inet adr/{print $4}'

If it doesn't work, post ifconfig's o/p.

Using grep and cut with awk is redundant but piping the result of an awk output to awk is ...:eek:

:rolleyes:

$ ifconfig eth0 | perl -ne 'if ( /inet addr:(^\s]+)/) { print $1; }'

Using Perl:

/sbin/ifconfig eth0 | perl -lne '/inet addr:([\d.]+)/ && print $1'

tyler_durden

Thank you all for your solution!
It works great!
Mn

ifconfig eth0|sed -n 's/^.*inet addr:\([0-9.]*\).*/\1/p'