[clue-tech] Re: regex smarties - what am I doing wrong?
David Rudder
david at reliableresponse.net
Wed Sep 3 12:19:52 MDT 2008
Grep will print the whole line. You can see the pattern matched, because
grep colorizes the match.
Try using awk instead. I simplified the Regexp, since awk was choking on
it. This seems to work:
grep newwave hosts | awk '/[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\./
{print $1}'
This will also match some invalid IP addresses, like those with 4 digits
numbers. A better awk person than I can probably fix this up.
-Dave
clue-tech-request at cluedenver.org wrote:
> Message: 6
> Date: Wed, 3 Sep 2008 10:16:56 -0600
> From: "David L. Willson" <DLWillson at TheGeek.NU>
> Subject: [clue-tech] regex smarties - what am I doing wrong?
> To: CLUE tech <clue-tech at cluedenver.org>
> Message-ID: <20080903161413.M5097 at TheGeek.NU>
> Content-Type: text/plain; charset=utf-8
>
> I'm trying to capture and return only the IP address from a line of text. I can match
> it, but something's wrong with the way I'm trying to capture it. Any thoughts?
>
> dlwillson at aurora:~
> $ grep newwave hosts | grep -E --color '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
> 69.88.86.210 newwaveenviro
>
> ^ That line does successfully color the IP address.
>
> dlwillson at aurora:~
> $ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\1/p'
> sed: -e expression #1, char 48: invalid reference \1 on `s' command's RHS
> dlwillson at aurora:~
> $ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\0/p'
> 69.88.86.210 newwaveenviro
> dlwillson at aurora:~
> $ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\1/p'
> sed: -e expression #1, char 48: invalid reference \1 on `s' command's RHS
> dlwillson at aurora:~
>
> Huh...
>
> -- David
>
>
>
> ------------------------------
>
> _______________________________________________
> clue-tech mailing list
> clue-tech at cluedenver.org
> http://www.cluedenver.org/mailman/listinfo/clue-tech
>
> End of clue-tech Digest, Vol 30, Issue 3
> ****************************************
>
More information about the clue-tech
mailing list