On Saturday 16 August 2008 06:44 in
<20080816054430.A3912477C3 at blf.utvinternet.co.uk>, Brian Foster wrote:
> | From: Marcus Furlong <furlongm at hotmail.com>
> | Date: Fri, 15 Aug 2008 23:22:32 +0100
> |[ ,.. ]
> | Some of the tags contain an attribute, say "my_attribute",
> | which according to the DTD, should only contain certain
> | values. If the value is not valid, I want to remove the
> | attribute entirely. E.g. if ASD SDF DFG FGH GHJ HJK are
> | the valid values for this attribute, then the following:
> |
> | <third my_attribute="ASD">
> | <third my_attribute="AD AD">
> | <third my_attribute="">
> | <third my_attribute="HJK">
> |
> | would become:
> |
> | <third my_attribute="ASD">
> | <third>
> | <third>
> | <third my_attribute="HJK">
> |
> |[ ... ] I'm sure there's a perl/sed one liner that could do it.
> | Does anyone know how it could be done somewhat more elegantly?
>> sed -e '
> s/ my_attribute="ASD"/@="ASD"/g
> s/ my_attribute="SDF"/@="SDF"/g
> s/ my_attribute="DFG"/@="DFG"/g
> s/ my_attribute="FGH"/@="FGH"/g
> s/ my_attribute="GHJ"/@="GHJ"/g
> s/ my_attribute="HJK"/@="HJK"/g
> s/ *my_attribute="[^"]*"//g
> s/@="/ my_attribute="/g
> '
>> rather common sed(1) trick.
Thanks Brian, works perfectly! :)
Could you explain what's happening in the above? I've searched for a similar
example with explanations but didn't find one, and now I'm all curious.
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!