From owner-freebsd-questions@FreeBSD.ORG Thu Oct 28 05:03:18 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA2AC106566B for ; Thu, 28 Oct 2010 05:03:18 +0000 (UTC) (envelope-from ws@au.dyndns.ws) Received: from ipmail07.adl2.internode.on.net (ipmail07.adl2.internode.on.net [150.101.137.131]) by mx1.freebsd.org (Postfix) with ESMTP id 5D4C38FC14 for ; Thu, 28 Oct 2010 05:03:17 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApEBACKdyEyWZWdv/2dsb2JhbAAH4gmFSAQ Received: from ppp103-111.static.internode.on.net (HELO [192.168.1.144]) ([150.101.103.111]) by ipmail07.adl2.internode.on.net with ESMTP; 28 Oct 2010 15:18:04 +1030 From: Wayne Sierke To: Liontaur In-Reply-To: References: <20101028010447.GA9734@thought.org> Content-Type: text/plain; charset="ISO-8859-1" Date: Thu, 28 Oct 2010 15:18:02 +1030 Message-ID: <1288241282.32933.82.camel@predator-ii.buffyverse> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 FreeBSD GNOME Team Port Content-Transfer-Encoding: 8bit Cc: Gary Kline , FreeBSD Mailing List Subject: Re: okay, time to ask the wizards. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Oct 2010 05:03:18 -0000 On Wed, 2010-10-27 at 18:16 -0700, Liontaur wrote: > On Wed, Oct 27, 2010 at 6:04 PM, Gary Kline 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/$//" 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