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

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