Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Mar 2016 09:56:01 -0500
From:      David Banning <david+dated+1457535364.ac3c82@skytracker.ca>
To:        Polytropon <freebsd@edvax.de>
Cc:        questions@freebsd.org
Subject:   Re: sed help please
Message-ID:  <20160304145601.GA24579@skytracker.ca>
In-Reply-To: <20160304053557.ff32d984.freebsd@edvax.de>
References:  <20160304040536.GA7729@skytracker.ca> <20160304053557.ff32d984.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Mar 04, 2016 at 05:35:57AM +0100, Polytropon wrote:
> On Thu, 3 Mar 2016 23:05:36 -0500, David Banning wrote:
> > I am trying to change hundreds of lines of text. Given the following text;
> > 
> > line 1
> > line 2 foo take this text
> > line 3
> > line 4
> > line 5 bar leave this text
> > line 6
> > line 7
> >  
> > I need a sed command that would take everything between foo and bar - 
> > including foo and bar.  
> > 
> > Ideally the output would look like;
> > 
> > line 1
> > line 2 
> > leave this text
> > line 6
> > line 7
> > 
> > Keep in mind that foo and bar appear in different 
> > locations - sometimes at the beginning of a line, sometimes at the end,
> > and sometimes in the middle.
> 
> Does it have to be sed? When I read your requirement, I immediately
> thought about the EXAMPLES section in "man awk", where you'll find:
> 
>        /start/, /stop/
>               Print all lines between start/stop pairs.
> 
> You could try this first:
> 
> 	awk -f '/foo/, /bar/' < input.txt > output.txt
> 
> Not verified, though.


It can't work with lines. Because I need keep the text before foo and 
after bar, and that text may or may not be on the same line with text that
needs to be saved or cut.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160304145601.GA24579>