Re: using grep to find IP address...

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/31/05


Date: Tue, 31 May 2005 11:38:03 -0500


Greg Beeker wrote:

>
> balgach@gmail.com wrote:
>
>>Hello all, i am interested in the last 255 bits of the local machines
>>ip address (aka the last number after the period) so far ive been
>>using the command, i know all the ip address start with 192.168
>>
>>ifconfig | grep '192.168' | awk '{print $2}'
>>
>>which is returning:
>>
>>inet addr:192.168.0.20
>>
>>
>>now how do i get it just to return the '20' ??
>
> ifconfig | grep '192.168' | awk '{print $2}' | awk -F. '{print $4}'
>

You never need grep and awk:

ifconfig | awk '/192.168/{print $2}' | awk -F. '{print $4}'

or even:

ifconfig | awk '/192.168/{split($2,f,".");print f[4]}'

Regards,

        Ed.



Relevant Pages

  • Re: using grep to find IP address...
    ... i am interested in the last 255 bits of the local machines ... > ip address (aka the last number after the period) so far ive been ... use Perl; ...
    (comp.unix.shell)
  • Re: using grep to find IP address...
    ... i am interested in the last 255 bits of the local machines ... > ip address (aka the last number after the period) so far ive been ... Depend on the rabbit's foot if you will, but remember, it didn't help the rabbit. ...
    (comp.unix.shell)
  • Re: using grep to find IP address...
    ... i am interested in the last 255 bits of the local machines ... > ip address (aka the last number after the period) so far ive been ... > Adam. ... Bill Seivert ...
    (comp.unix.shell)
  • Re: using grep to find IP address...
    ... i am interested in the last 255 bits of the local machines ... > ip address (aka the last number after the period) so far ive been ... Thorn ... "I am not sure what this is, but an `F' would only dignify it." ...
    (comp.unix.shell)