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
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!