On 27 Sep 2004, at 17:23, Lee Hosty wrote:
> On Mon, 27 Sep 2004, Lee Hosty wrote:
>>> On Mon, 27 Sep 2004, John Allen wrote:
>>>>> On Monday 27 September 2004 15:19, Gareth Eason wrote:
>>>> There is probably a better way, but I would crack out the perl on
>>>> this
>>>> one.
>>>>>>>>>> Or
>>> # perl -pi -e 's|<div class="foo"></div>|<div
>>> class="foo">TEST</div>|g' foobar.html
>>>> perl -pi.bak -e 'if (!($. % 3)) { s|<div class="foo"></div>|<div
>> class="foo">TEST</div>|g; }" foobar.html
>> Bah, sorry. That last " should be a ' of course. Or just add:
>> if !($.%3)
>> to the end of Johns, like so:
>> perl -pi -e 's|<div class="foo"></div>|<div class="foo">TEST</div>|g
> if !($.%3)' foobar.html
Doesn't work either. Would work for the little example given, but AFAIR
the original poster said he needed to change every third occurence of
<div class="foo"></div> to <div class="foo">TEST</div> and the above
only works where the file looks just like the little sample he gave. As
that is a pointless piece of HTML I think it's fair to assume that the
real source files looks a little different.Using $. as a counter won't
necessarily work.
Niall
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!