[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