Subject: Re: printing a regular expression match
To: Michael Gorsuch <michael.gorsuch@gmail.com>
From: =?ISO-8859-1?Q?Sten_Daniel_S=F8rsdal?= <lists@wm-access.no>
List: netbsd-users
Date: 12/08/2006 23:37:50
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.
>=20
> For example,
>=20
> echo [1234] | egrep \(1234\)
>=20
> It matches the expression, but I only want to print the match, '1234'.
>=20
> Any ideas? I'm sure there's a unix tool I'm not using properly here...=
>=20
Would this work for you?
echo '[1234]' | sed 's/[^[:digit:]+]//g'
I had troubles getting backreferences work as i didn't find any good
examples and the documentation (re_format/regex). This was using FreeBSD
6.1 "sed" so YMMV.
In ultraedit (windows app) i would do this:
input: [1234]
replace: ^[^\d](\d+)[^\d]$
with: \1
result: 1234
--=20
Sten Daniel S=F8rsdal