Re: using grep to find IP address...

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


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.



Relevant Pages

  • Re: lightweight internet browser
    ... and insults anyone that doesn't use the command line in Linux as their ... ''Sidney'' aka ''Tom Newton'' aka ''Alan Connor'' aka a string of other ... Take, for example, his stance on the command line: ... he claims it to be his preferred environment, ...
    (comp.os.linux.misc)
  • Re: rm -rf *.orig not working
    ... The rm command does not see the wildcard character, ... Jakub Fišer AKA mr@xxxxxxxxxxxx ... ICQ: I don't see kyou - http://icq.xmpp.cz/ ...
    (alt.os.linux)
  • How to change the directory for a debug log file?
    ... I want to generate a log file for debugging output. ... I want it in my project's debug directory. ... I enter the following for Command Arguments: ... aka $. ...
    (microsoft.public.vc.language)
  • Re: Downloading Headers
    ... That's the way the Headers button (aka Get Next... ... the Synchronize Newsgroup command with just Get messages marked ... Robert Aldwinckle ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Problem when redeined macro for floats with usepackage{color}
    ... tables) so that single spacing is used. ... % - User can specify draft copies, ... The \beforepreface command creates the title page, ...
    (comp.text.tex)