From owner-freebsd-questions@freebsd.org Fri Mar 4 14:56:09 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CDF859DAC38 for ; Fri, 4 Mar 2016 14:56:09 +0000 (UTC) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id B8DFF863 for ; Fri, 4 Mar 2016 14:56:09 +0000 (UTC) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) Received: by mailman.ysv.freebsd.org (Postfix) id B42D39DAC37; Fri, 4 Mar 2016 14:56:09 +0000 (UTC) Delivered-To: questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B3C6E9DAC36 for ; Fri, 4 Mar 2016 14:56:09 +0000 (UTC) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) Received: from 3s1.com (3s1.com [162.213.106.199]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "3s1.com", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 38BBB862 for ; Fri, 4 Mar 2016 14:56:08 +0000 (UTC) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) Received: from 3s1.com (localhost [127.0.0.1]) by 3s1.com (8.14.9/8.14.9) with ESMTP id u24Eu6IT024697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 4 Mar 2016 09:56:06 -0500 (EST) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) Received: (from david@localhost) by 3s1.com (8.14.9/8.14.9/Submit) id u24Eu5wU024696 for questions@freebsd.org; Fri, 4 Mar 2016 09:56:05 -0500 (EST) (envelope-from david+dated+1457535364.ac3c82@skytracker.ca) X-Authentication-Warning: 3s1.com: david set sender to david+dated+1457535364.ac3c82@skytracker.ca using -f Received: by 3s1.com (tmda-sendmail, from uid 1000); Fri, 04 Mar 2016 09:56:02 -0500 Date: Fri, 4 Mar 2016 09:56:01 -0500 To: Polytropon Cc: questions@freebsd.org Subject: Re: sed help please Message-ID: <20160304145601.GA24579@skytracker.ca> References: <20160304040536.GA7729@skytracker.ca> <20160304053557.ff32d984.freebsd@edvax.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160304053557.ff32d984.freebsd@edvax.de> User-Agent: Mutt/1.4.2.3i X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: David Banning X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2016 14:56:09 -0000 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.