Re: using grep to find IP address...
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/31/05
- Next message: Janis Papanagnou: "Re: Executing command in Shell"
- Previous message: Ed Morton: "Re: using grep to find IP address..."
- In reply to: balgach_at_gmail.com: "using grep to find IP address..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 May 2005 11:48:12 -0500
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
That seems unlikey. awk splits records into fields at spaces by default
and you're only asking it to print one field so seeing output with a
space in that field would be a tad odd.
>
> now how do i get it just to return the '20' ??
Let's assume that the ifconfig line you're interested in looks like this:
...
inet addr:192.168.0.20 Bcast:192.168.99.255 Mask:255.255.255.0
...
then your command above:
ifconfig | grep '192.168' | awk '{print $2}'
would output:
addr:192.168.0.20
Alternatively, specify either "." or a space char as the separator:
ifconfig | awk -F"[. ]" '/192.168/{print $5}'
to get an output of just "20". If there's tabs, adjust to suit....
Regards,
Ed.
- Next message: Janis Papanagnou: "Re: Executing command in Shell"
- Previous message: Ed Morton: "Re: using grep to find IP address..."
- In reply to: balgach_at_gmail.com: "using grep to find IP address..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|