Subject: Re: printing a regular expression match
To: None <netbsd-users@netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-users
Date: 12/08/2006 20:47:15
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,'

I hope I didn't just do your homework because I hate homework.

-- 
Christian