From owner-freebsd-questions@freebsd.org Fri Mar 4 04:36:07 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 824429DA2FB for ; Fri, 4 Mar 2016 04:36:07 +0000 (UTC) (envelope-from freebsd@edvax.de) 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 6F80BD7B for ; Fri, 4 Mar 2016 04:36:07 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: by mailman.ysv.freebsd.org (Postfix) id 6B17B9DA2FA; Fri, 4 Mar 2016 04:36:07 +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 6AAD09DA2F9 for ; Fri, 4 Mar 2016 04:36:07 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3552AD7A for ; Fri, 4 Mar 2016 04:36:06 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de (port-92-195-57-156.dynamic.qsc.de [92.195.57.156]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id 8AB5F2763C; Fri, 4 Mar 2016 05:35:58 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id u244ZvOT003140; Fri, 4 Mar 2016 05:35:58 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Fri, 4 Mar 2016 05:35:57 +0100 From: Polytropon To: David Banning Cc: questions@freebsd.org Subject: Re: sed help please Message-Id: <20160304053557.ff32d984.freebsd@edvax.de> In-Reply-To: <20160304040536.GA7729@skytracker.ca> References: <20160304040536.GA7729@skytracker.ca> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 04:36:07 -0000 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. > I found someone who posted the following > solution; > > sed '/foo/,/bar/{s/./x/g}' file > > but I found that this does not execute under FreeBSD. I have looked > around for differences between FreeBSD and other unix like SED operations > but only see the -s "", regarding backup file. If this works in GNU sed, you can install it (textproc/gsed) and the use this command. > Any pointers would be helpful. void *some, *helpful, *pointers; :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...