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

next in thread | previous in thread | raw e-mail | index | archive | help
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





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