[clue-tech] Re: regex smarties - what am I doing wrong?
David L. Willson
DLWillson at TheGeek.NU
Wed Sep 3 15:34:18 MDT 2008
On Wed, 3 Sep 2008 15:10:22 -0600, David L. Willson wrote
> $ 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
> ------------------------------
> Mike: Does escaping the open and closed parenths help?
> ------------------------------
> Surprise to me, yes, it does. I don't get the error any more. But I also
> don't get just the IP address, I get the whole line... <mumble>
>
> What I'm trying to do is to grep a trashy list of names, nicknames, aliases,
> and IP addresses for (something), and in the case of a unique hit, return the
> IP address only, and an error of either "not found" or "not found uniquely" in
> the appropriate other cases.
>
> The first step, where I currently am stuck, is how to return only the IP
> address, rather than the whole line. The rest should be a doddle. (remember
> Lemmings?)
>
> I'll keep trying and let you know if I figure it out.
Here is the line I'm currently using to test
echo -e "1.2.3.4 1234host\notherhost 123.45.67.89" | \
sed -e 's/\(\([[:digit:]]{1,3}\.\){3}[[:digit:]]{1,3}\)/\1/g'
It ought to return, well, ultimately, a "non-unique" error, but for now, it should
return each IP address on it's own line, stripped of all the leading and trailing trash.
In stead, I get back everything I feed in, no stripping.
More information about the clue-tech
mailing list