[SunHELP] sed, newline handling
     
    
       
    Wed Feb 12 15:47:06 CST 2003
    
    
  
Rich this is great.  One final kicker, if you don't mind =).
what would I do in a scenario as such:
This
is
a
test
This
is
a 
test
...
expected output:
This,is,a,test
This,is,a,test
...
-----Original Message-----
From: Rich Kulawiec [mailto:rsk at gsp.org] 
Sent: Wednesday, February 12, 2003 4:27 PM
To: Markham, Richard
Subject: Re: [SunHELP] sed, newline handling
On Wed, Feb 12, 2003 at 03:48:32PM -0500, Markham, Richard wrote:
> I need to be able to remove new lines:
> This
> is
> a
> test
> 
> Thisisatest
> 
> also would like the option to replace newlines:
> This
> is
> a
> test
> 
> This,is,a,test
Don't use sed. ;-)  It's much easier and faster with tr:
	tr -d "\012" < infile > outfile
will remove all the newlines.  If you need to have one and only one at the
end of the file:
	tr -d "\012" < infile > outfile
	echo "" >> outfile
For your second example:
	tr "\012" "," < infile > outfile
and again, if you want a trailing newline:
	tr "\012" "," < infile > outfile
	echo "" >> outfile
(Why the \012?  Octal code for newline and one of the ways to 
specify a particular character to tr.)
---Rsk
    
    
More information about the SunHELP
mailing list