Subject: Re: printing a regular expression match
To: Mike M. Volokhov <mishka@netbsd.org>
From: Michael Gorsuch <michael.gorsuch@gmail.com>
List: netbsd-users
Date: 12/08/2006 15:25:46
Thanks all - no, it's not my homework.  I was trying to think of this ealier
to solve a real life sysadmin issue ;-)

I appreciate it.

On 12/8/06, Mike M. Volokhov <mishka@netbsd.org> wrote:
>
> Christian Biere <christianbiere@gmx.de> wrote:
> > Michael Gorsuch wrote:
> > > Hey all, I'm trying to find the right Unix tool to print out a matched
> > > regular expression, not just a line that matches.
> > >
> > > For example,
> > >
> > > echo [1234] | egrep \(1234\)
> > >
> > > It matches the expression, but I only want to print the match, '1234'.
> >
> > I don't know which shell you use but I'd recommend to use quotes to
> prevent
> > clashes with shell meta-characters:
> >
> > echo '[1234]' | egrep '\(1234\)' | sed 's,^.*\(1234\).*$,\1,'
>
> Also, it's possible to use perl regex - $& will contain matched string.
>
> > I hope I didn't just do your homework because I hate homework.
>
> Or you love homework, or homework loves you :-)
>
> --
> Mishka
>
>


-- 
http://www.styledbits.com: The Musings of a Maddened Sysadmin