Re: trouble with `sed -r` and specifying occurrence



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?
.



Relevant Pages

  • STS-121 MCC Status Report #05
    ... STATUS REPORT: STS-121-05 ... the first time in more than three years, and for the first time ever that ... crew includes an American, ... feet directly below the station to perform the rendezvous pitch maneuver: ...
    (sci.space.shuttle)
  • Titanic stars Winslet, DiCaprio to reunite for Sam Mendes drama
    ... It will be the first time Mendes has directed his wife, ... the report added. ... The reunion of DiCaprio and Winslet brings together two of the hottest ...
    (rec.arts.movies.current-films)
  • Re: I Hate this kind of problem. Please Help
    ... Ok - to narrow this down, it's only happening during the FIRST time this is ... a few times the data environment / data session got switched ... I added a go top to the code after the select and before the report and I ... If I put the BROWSE after the REPORT command, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Have England almost got a steady XI?
    ... the first time in a while it seems as though the majority of the ... FWIW, some of the Australian posters over on rsc are distinctly ... The Aussies don't seem to rate Andrew MacDonald, ... injury prone than Fred, Hauritz as the sole spinner, Hussey who is out ...
    (uk.sport.cricket)
  • Japan military picks Eurocopter for first time: official
    ... Japan military picks Eurocopter for first time: ... CA - Japan's military will for the first time buy ... U.S. and friendly nation laws prohibit fully ... with our laws this report cannot be provided in ...
    (soc.culture.japan)