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

[ILUG] Re: Re: Re: sed question

Marcus Furlong furlongm at hotmail.com
Sat Aug 16 16:33:02 IST 2008


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.




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