Re: How to remove trailing commas and points from a CSV file ?



On Fri, Jun 27, 2008 at 12:26 AM, Erasmo Perez <perez.erasmo@xxxxxxxxx> wrote:


a,b,.,.,.,.,.,.,.
b,c,d,.,.,.,.,.,.
e,f,g,h,.,.,.,.,.
i,j,k,l,m,.,.,.,.

and so on

My problem: how could I get rid of the trailing points and commas, so
the output CSV file could get following neat format (without the
trailing points and its commas separators):

a,b
b,c,d
e,f,g,h
i,j,k,l,m


Hello,

Follow your sample data, you may try:

use strict;

while(<DATA>) {
s/(\,\.)+$//;
print;
}

__DATA__
a,b,.,.,.,.,.,.,.
b,c,d,.,.,.,.,.,.
e,f,g,h,.,.,.,.,.
i,j,k,l,m,.,.,.,.


The output is:

a,b
b,c,d
e,f,g,h
i,j,k,l,m

--
Jeff Peng - Peng.Kyo@xxxxxxxxx
http://home.arcor.de/mailerstar/jeff
.



Relevant Pages