Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Oct 2010 09:29:27 -0700
From:      Gary Kline <kline@thought.org>
To:        Wayne Sierke <ws@au.dyndns.ws>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>, Liontaur <liontaur@gmail.com>
Subject:   Re: okay, time to ask the wizards.
Message-ID:  <20101028162927.GA11082@thought.org>
In-Reply-To: <1288241282.32933.82.camel@predator-ii.buffyverse>
References:  <20101028010447.GA9734@thought.org> <AANLkTikF%2BkB5v9pBn5hVMUg7wS78fbO%2BU9G8abNeQA%2BZ@mail.gmail.com> <1288241282.32933.82.camel@predator-ii.buffyverse>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Oct 28, 2010 at 03:18:02PM +1030, Wayne Sierke wrote:
> On Wed, 2010-10-27 at 18:16 -0700, Liontaur wrote:
> > On Wed, Oct 27, 2010 at 6:04 PM, Gary Kline <kline@thought.org> wrote:
> > 
> > > I've got a very large file with paragraphs separated only by "\n".
> > > How do I put a blank line _after_ each newline?
> > >
> > >
> > Perhaps using sed? i'm definitely no sed expert but the substitute command
> > would work, just substitute one \n with two?
> > 
> > Mark
> 
> Not quite. When considering sed(1), recall that:
> 
>         Normally, sed cyclically copies a line of input, not including
>         its terminating newline character, into a pattern space, ...
>         (then) copies the pattern space to the standard output,
>         appending a newline, and deletes the pattern space.
> 
> So there is no "\n" in the initial pattern space to be substituted.
> Characters can however be inserted at the end of the line (before the
> original \n) with: "s/$/<text to insert>/" as Chad used in his perl
> solution. Unfortunately FreeBSD sed's "substitute" doesn't recognise
> "\n" as "newline"  in a substitution, although it's possible to insert a
> literal "newline" character through various shell-dependent techniques.
> 
> In this particular case however, sed does offer the "pièce de
> résistance":
> 
>         sed G
> 
> 
> The operation is left as a learning exercise for the reader.
> 
> 
> Wayne
> 


	Well, I hope this mouse and paste works across konsoles.  I've
had this stuff in my ~/.HowTo file for a couple years.  I don't
remember the  % sed G bit, but it would've saved a lot of electrons.


%%% sed howto's:

FILE SPACING:

 # double space a file
 sed G

 # double space a file which already has blank lines in it. Output
file
 # should contain no more than one blank line between lines of text.
 sed '/^$/d;G'

 # triple space a file
 sed 'G;G'


	Yup.  Works.  So there, gents, you've got it from "wherever I
	got it from."

	thanks for the insights from ``y'all|you-all|you'n's|everybody''

	gary



> 

-- 
 Gary Kline  kline@thought.org  http://www.thought.org  Public Service Unix
    The 7.90a release of Jottings: http://jottings.thought.org/index.php
                           http://journey.thought.org
                                        



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101028162927.GA11082>