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

[ILUG] Re: sed question

Marcus Furlong furlongm at hotmail.com
Thu Aug 14 14:20:32 IST 2008


Andrew McGill <glug <at> lunch.za.net> writes:

> 
> On Thursday 14 August 2008 13:52:51 Marcus Furlong wrote:

> > The "first" tags have no closing tags at all, and may or may not have
> > text between the tag and the next tag. What I want to do is remove the
> > "first" tag and any text up to, but not including the "second" tag.
> >
> > I've got to the following stage, but don't know how to get it to _not_
> > delete the line containing the "second" tag:
> >
> > sed -e '<first/,/<second s/.*//' file.xml
> Sed doesn't do multi-line search and replace - but perl can, if you add "s".  
> You can do it like this:
> 
> perl -p -e 'undef $/; s{<first.*?(<second)}{$1}sg' < filename.xml
> 
> That will work provided "first" is not on the first line of the input file.  
> It sucks the whole thing into memory, and treats it as one line.  If your 
> file is over a few hundred Mb, you won't like this approach.

"first" is also on the first line of the input file. Apart from that it works
fine, thanks. Does anyone know a one-liner sed/awk/perl to add a blank line to
the start of a file? It seems to work fine if I add a blank line.

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