On Wed, 24 Mar 2010 13:06:12 -0700 Philip Guenther wrote:

> On Wed, Mar 24, 2010 at 10:17 AM, Christopher Zimmermann
> <madro...@zakweb.de> wrote:
> > On Wed, 24 Mar 2010 19:00:06 +0200 Gregory Edigarov wrote:
> >> Just wonder how could one implement what gnu grep -o flag does using
> >> our toolchain?
> >>
> >> from ggrep(1):
> >>
> >>  -o, --only-matching
> >>               Show  only the part of a matching line that matches
> >>               PATTERN.
> >
> > maybe try this:
> > sed -n -e 's/.*\(PATTERN\).*/\1/ -e /PATTERN/p
> 
> 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'

right. This one looks nicer.

> If you need extended (egrep-style) regexps, then the most portable
> solution is a chunk of awk (left as an exercise for the student); the
> less-portable-but-works-in-4.7 solution is to use -E option to sed:
>     sed -n -E 's/.*(PATTERN).*/\1/p'

sed -E !?! Great! Now I know why I upgraded to -current.

Reply via email to