[clue-tech] Re: regex smarties - what am I doing wrong?

David L. Willson DLWillson at TheGeek.NU
Wed Sep 3 16:01:16 MDT 2008


On Wed, 03 Sep 2008 15:36:52 -0600, Patrick H. wrote
> I think this is the sed you want
> sed -e 's/\(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}\).*/\1/'

Closer, but not there yet.

$ echo -e "98.76.54.32 Alice\nBob 123.45.67.89\nCarol or Dave 064.032.016.008\n" 
98.76.54.32 Alice
Bob 123.45.67.89
Carol or Dave 064.032.016.008

$ echo -e "98.76.54.32 Alice\nBob 123.45.67.89\nCarol or Dave 064.032.016.008\n" \
> | sed -e 's/\(\([[:digit:]]\{1,3\}\.\)\{3\}[[:digit:]]\{1,3\}\).*/\1/'
98.76.54.32
Bob 123.45.67.89
Carol or Dave 064.032.016.008

As you can see, the Alice line is properly trimmed, but not the other lines.  Now, I
have two questions:  Why don't the single quotes preserve the sed command properly
without all the escaping of the special chars?  And, why doesn't the second close-paren
close the pattern-capture?  Regexes are hard...


More information about the clue-tech mailing list