Subject: Re: printing a regular expression match
To: Michael Gorsuch <michael.gorsuch@gmail.com>
From: Mike M. Volokhov <mishka@netbsd.org>
List: netbsd-users
Date: 12/08/2006 19:42:33
Michael Gorsuch <michael.gorsuch@gmail.com> 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'.
> 
> Any ideas?  I'm sure there's a unix tool I'm not using properly here...

echo "[1234]" | grep -o '1234'

--
Mishka