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] Re: sed question

[ILUG] Re: sed question

Marcus Furlong furlongm at hotmail.com
Thu Aug 14 16:13:09 IST 2008


Marcus Furlong <furlongm <at> hotmail.com> writes:

> 
> Hi,
> 
> I'm having trouble using sed to do replacements on some badly tagged
> xml. I have a large number of files that are tagged as follows:

Ok this problem is fixed now, but it introduced another smaller one...

So I have other tags as follows:

<third> lots of text
<third> lots of text
<third> lots of text
<third> lots of text
<third> lots of text

Modifying the previous perl example I tried to add the closing tags as follows:

perl -pi -e 'undef $/; s{(<third.*?)(<third)}{$1</third>\n$2}sg'

The problem is that this only works for every other "third" tag, because the
opening tag becomes part of the regexp matched pattern and isn't processed in
the following match. E.g it becomes:

<third> lots of text</third>
<third> lots of text
<third> lots of text</third>
<third> lots of text
<third> lots of text</third>

Running the script twice doesn't help either as it matches those that are
already done, and again skips the following one:

<third> lots of text</third></third>
<third> lots of text
<third> lots of text</third></third>
<third> lots of text
<third> lots of text</third></third>

Any ideas on how to this one? Thanks,

Marcus





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