From owner-freebsd-questions@freebsd.org Fri Mar 4 15:56:29 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 6EB869DA3E5 for ; Fri, 4 Mar 2016 15:56:29 +0000 (UTC) (envelope-from wblock@wonkity.com) 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 5BD04E2A for ; Fri, 4 Mar 2016 15:56:29 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: by mailman.ysv.freebsd.org (Postfix) id 56CAC9DA3E4; Fri, 4 Mar 2016 15:56:29 +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 565DC9DA3E3 for ; Fri, 4 Mar 2016 15:56:29 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (wonkity.com [67.158.26.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "wonkity.com", Issuer "wonkity.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 2A0AEE29 for ; Fri, 4 Mar 2016 15:56:28 +0000 (UTC) (envelope-from wblock@wonkity.com) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.15.2/8.15.2) with ESMTPS id u24FuRJw010167 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 4 Mar 2016 08:56:27 -0700 (MST) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.15.2/8.15.2/Submit) with ESMTP id u24FuR29010164; Fri, 4 Mar 2016 08:56:27 -0700 (MST) (envelope-from wblock@wonkity.com) Date: Fri, 4 Mar 2016 08:56:27 -0700 (MST) From: Warren Block To: David Banning cc: questions@freebsd.org Subject: Re: sed help please In-Reply-To: <20160304040536.GA7729@skytracker.ca> Message-ID: References: <20160304040536.GA7729@skytracker.ca> User-Agent: Alpine 2.20 (BSF 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (wonkity.com [127.0.0.1]); Fri, 04 Mar 2016 08:56:27 -0700 (MST) 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 15:56:29 -0000 On Thu, 3 Mar 2016, 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. 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. FreeBSD's sed and awk are... well, let's say "historical". Perl has much more powerful regular expressions, character classes, and slurp mode. However, this bit of Perl reads a file from stdin or as a following argument and removes everything between the "foo" and "bar", inclusive: perl -0777 -pe 's/foo.*?bar//sg'