From owner-freebsd-questions Thu Mar 18 15:37:50 1999 Delivered-To: freebsd-questions@freebsd.org Received: from cc942873-a.ewndsr1.nj.home.com (cc942873-a.ewndsr1.nj.home.com [24.2.89.207]) by hub.freebsd.org (Postfix) with ESMTP id 82406153EC for ; Thu, 18 Mar 1999 15:37:45 -0800 (PST) (envelope-from cjc@cc942873-a.ewndsr1.nj.home.com) Received: (from cjc@localhost) by cc942873-a.ewndsr1.nj.home.com (8.9.3/8.8.8) id SAA13207; Thu, 18 Mar 1999 18:36:09 -0500 (EST) (envelope-from cjc) From: "Crist J. Clark" Message-Id: <199903182336.SAA13207@cc942873-a.ewndsr1.nj.home.com> Subject: Re: sed and newlines In-Reply-To: <199903180948.JAA10316@keep.lan.Awfulhak.org> from Brian Somers at "Mar 18, 99 09:48:36 am" To: brian@Awfulhak.org (Brian Somers) Date: Thu, 18 Mar 1999 18:36:09 -0500 (EST) Cc: cjclark@home.com, freebsd-questions@FreeBSD.ORG Reply-To: cjclark@home.com X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Brian Somers wrote, > > The sed manpage says, > > > > Sed Regular Expressions > > The sed regular expressions are basic regular expressions (BRE's, see > > regex(3) for more information). In addition, sed has the following two > > additions to BRE's: > > . > > . > > . > > 2. The escape sequence \n matches a newline character embedded in the > > pattern space. You can't, however, use a literal newline character > > in an address or in the substitute command. > > > > If I am reading this correctly, > > > > % sed 's/\n/ /' file > > > > Should take the file and subsitute three spaces in place of every > > newline. However, it does not. It does not seem to understand '\n.' > > > > In spite of what it says, I have tried literal newlines (with \ and > > ^V), and as claimed on the manpage, it does not work (it will > > generate errors). > > > > Am I missing something obvious? Or is sed broken? > > Sed performs commands on each line. A line is read in and the > newline is removed. The command(s) are executed and the pattern > space is output with a trailing newline. Thanks for all of the replies on this. I realized what was happening when I actually had the time and energy to peak at the sed source code. Silly, me, just because the name 'sed' is short for 'stream editor,' I assumed it really read the input as a stream rather than line-by-line. > The ``tr'' command is probably more appropriate > for this sort of thing. For my example, yes, but in real life, I was only removing newlines on lines with specific regexps in them. 'tr' was not up to that job. Thanks again for the replies everyone. -- Crist J. Clark cjclark@home.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message