| 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.
cheers!
-blf-
--
“How many surrealists does it take to | Brian Foster
change a lightbulb? Three. One calms | somewhere in south of France
the warthog, and two fill the bathtub | Stop E$$o (ExxonMobil)!
with brightly-coloured machine tools.” | http://www.stopesso.com
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!