On Wed, Mar 24, 2010 at 2010-03-24 21:13:40, Philip Guenther
<guent...@gmail.com> wrote: ...

> > Hmm, missing quote, and the expressions can be combined, but as a
> > portable solution this is indeed the right answer.
> >    sed -n -e 's/.*\(PATTERN\).*/\1/p'
>
> Actually, there are two bug in that, an obvious one and a subtle one.
> The obvious one is that it only prints one match per line instead of
> printing all the matches.  The subtle one is that if the pattern can
> match in multiple overlapping positions, it will report the match with
> the *latest* start instead of the *earliest* start (because the
> leading ".*" is greedy).
>
> The 'portable' solution that doesn't have those problems is to use a
> nuke^W^Wperl:
>     perl -nle 'while(m((PATTERN))g){print $1}'
>
>
> Philip Guenther
>

I'm sure there is a case in which sed should be used instead of perl,
but I haven't run across it yet.
-- 

Edward Ahlsen-Girard
Ft Walton Beach, FL

Reply via email to