Re: trouble with `sed -r` and specifying occurrence
- From: William Pursell <bill.pursell@xxxxxxxxx>
- Date: Mon, 15 Sep 2008 21:59:29 -0700 (PDT)
On 16 Sep, 04:26, wick end <n_b_a_...@xxxxxxxxxx> wrote:
sed -r 's|\(\[[Uu][Rr][Ll]=\)\(.*\)\(\]\)\(\[\[color=.*\]\)\(.*\)\(\[\/
color\]\]\)\(\[\/[Uu][Rr][Ll]\]\)|<a href="\2">\5<\/a>|'
that complains :
-------------------
sed: -e expression #1, char 124: invalid reference \5 on `s' command's
RHS
FWIW, your expression works just fine for me without the -r.
Sadly, the sed that I'm using doesn't report its version number,
it is whatever ships with OSX, Darwin kernel 9.4.0 (I'm not
a big Mac fan, and this is the first time I've run uname on this
machine...but WTF? Shouldn't there be some relationship
between the kernel and the 10.5.4 version number on
the OS itself? I hate marketing names...does "Darwin"
mean 10.5.4, or 10.5, or kernel 9.4....yechh...fortunately
that is an off topic rant.)
It seems odd to me that you explicitly use \(\) bracketing
around expressions that you discard. Your sed command
would be simpler if you only save the patterns you need
and make the replacement be:
<a href="\1">\2<\/a>
The error you're getting sounds like some of the
earlier expressions are matching more than you
expect. You might try doing things like:
[^]]* instead of .* to match up to the next
closing brace.
It sounds like your expression works for you some of
the time, but not always. Do you have sample input
on which it fails?
.
- Follow-Ups:
- Re: trouble with `sed -r` and specifying occurrence
- From: wick end
- Re: trouble with `sed -r` and specifying occurrence
- References:
- trouble with `sed -r` and specifying occurrence
- From: wick end
- trouble with `sed -r` and specifying occurrence
- Prev by Date: Re: tr and line-oriented buffer
- Next by Date: Re: trouble with `sed -r` and specifying occurrence
- Previous by thread: trouble with `sed -r` and specifying occurrence
- Next by thread: Re: trouble with `sed -r` and specifying occurrence
- Index(es):
Relevant Pages
|