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?



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/


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links