Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed/vi how to concatenate all non-empty lines?



Thanks for the Perl cheat!

Jc

>From: Shimpei Yamashita <shimpei@example.com>
>Reply-To: tlug@example.com
>To: tlug@example.com
>Subject: Re: sed/vi how to concatenate all non-empty lines?
>Date: Wed, 25 Jul 2001 20:42:19 +0900
>
>On Wed, Jul 25, 2001 at 08:28:04AM +0000, Jean-Christian Imbeault wrote:
> > Update,
> >
> > col and the script you provided work fined, except that it removed all 
>blank
> > lines :) I was hoping to keep the blank lines as they separated the
> > paragraphs from each other . . .
>
>I'm going to cheat and use a short perl script. :-p
>
>#! /usr/bin/perl -w
>
>$/ = undef;   # slurp in the entire file using <STDIN>
>while (<STDIN>) {
>   s/([^\n])\n([^\n])/$1 $2/g; # convert non-consecutive end-of-lines
>                               # to space
>   print;
>}
>
>Save this script as, say, concatLines, chmod it to 755, and run it like 
>this:
>
>col originalfile.txt | concatLines > output.txt
>
>--
>Shimpei Yamashita                               http://www.shimpei.org/
>
>-----------------------------------------------------------------------
>Next Nomikai Meeting:    Fri, Aug 10 19:30-  Tengu Tokyo Eki-Mae
>Next Technical Meeting:  Sat, Sep 15 13:30-  Akasaka Kumin Center
>-----------------------------------------------------------------------
>more info: http://www.tlug.gr.jp           Sponsor: Global Online Japan
>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links