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

Gareth Eason bigbro at skynet.ie
Mon Sep 27 15:19:42 IST 2004


	There is probably a better way, but I would crack out the perl on this one.

	open( FILE, "foobar.html" ) or die;
	open( OUTFILE, ">output.html" ) or die;
	my $counter = 0;

	while(<FILE>)
	{
		if( /<div class="foo"><\/div>/ )
		{
			$counter++;
			if( $counter == 3 )
			{
				$counter = 0;
				s/<div class="foo"><\/div>/<div class="foo">TEST<\/div>/;
			}
		}
		print OUTFILE $_;
	}


	Jobsa... (Usual disclaimers, typos, etc. apply, YMMV.)

	Best regards,
	-->Gar
			

Rory Winston wrote:
> Regex gurus,
> 
> I'm trying to do a simple substitute in Vim. I hav a HTML page with hundreds
> of lines like:
> 
> <div class="foo"></div>
> <div class="foo"></div>
> <div class="foo"></div>
> <div class="foo"></div>
> 
> What I would like to be able to do is replace every n'th element with
> something else. So if n = 3, then the result is:
> 
> <div class="foo"></div>
> <div class="foo"></div>
> <div class="foo">TEST</div>
> <div class="foo"></div>
> <div class="foo"></div>
> <div class="foo">TEST</div>
> 
> Does anybody know how I might achieve this?
> 
> Thanks in advance,
> Cheers,
> 
> Rory
> 



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