LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Regex Question

[ILUG] Regex Question

Niall O Broin niall at linux.ie
Mon Sep 27 17:50:40 IST 2004


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




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell