okay, time to ask the wizards.
Gary Kline
kline at thought.org
Thu Oct 28 16:29:53 UTC 2010
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 at 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 at 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
More information about the freebsd-questions
mailing list