From owner-freebsd-questions Thu Mar 18 1:53: 6 1999 Delivered-To: freebsd-questions@freebsd.org Received: from awfulhak.org (awfulhak.force9.co.uk [195.166.136.63]) by hub.freebsd.org (Postfix) with ESMTP id 9CE6314E68 for ; Thu, 18 Mar 1999 01:53:02 -0800 (PST) (envelope-from brian@Awfulhak.org) Received: from keep.lan.Awfulhak.org (keep.lan.Awfulhak.org [172.16.0.8]) by awfulhak.org (8.9.2/8.8.8) with ESMTP id JAA47170; Thu, 18 Mar 1999 09:52:40 GMT (envelope-from brian@Awfulhak.org) Received: from keep.lan.Awfulhak.org (localhost [127.0.0.1]) by keep.lan.Awfulhak.org (8.9.3/8.9.3) with ESMTP id JAA10316; Thu, 18 Mar 1999 09:48:36 GMT (envelope-from brian@keep.lan.Awfulhak.org) Message-Id: <199903180948.JAA10316@keep.lan.Awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: cjclark@home.com Cc: freebsd-questions@FreeBSD.ORG (FreeBSD Questions) Subject: Re: sed and newlines In-reply-to: Your message of "Wed, 17 Mar 1999 18:39:00 EST." <199903172339.SAA06674@cc942873-a.ewndsr1.nj.home.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 18 Mar 1999 09:48:36 +0000 From: Brian Somers Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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. The only time you ever see a newline in the pattern space is if you put it there yourself (with ``N'' for example). Something like sed -e :x -e N -e 's/\n/ /' -e '$p' -e 'b x' will work, but it's not the most elegant way as it ends up buffering your entire file. The ``tr'' command is probably more appropriate for this sort of thing. > Thanks. > -- > Crist J. Clark cjclark@home.com -- Brian Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message