[ILUG] Re: Re: sed question
Brian Foster
blf at utvinternet.ie
Sat Aug 16 06:44:30 IST 2008
| 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
More information about the ILUG
mailing list