Erasmo Perez wrote:
Hi dear list:

Hello,

Please forgive my lack of Perl credentials, but i am a complete beginner

But, and that is the problem, I do have an urgent issue and that's why
I came to perl in the very first instance

I have a CSV file, which comes in the following format:

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

$ perl -le'
my @x = qw[
    a,b,.,.,.,.,.,.,.
    b,c,d,.,.,.,.,.,.
    e,f,g,h,.,.,.,.,.
    i,j,k,l,m,.,.,.,.
    ];

for my $line ( @x ) {
    print $line;
    $line =~ s/(?:,\.)+$//;
    print $line;
    }
'
a,b,.,.,.,.,.,.,.
a,b
b,c,d,.,.,.,.,.,.
b,c,d
e,f,g,h,.,.,.,.,.
e,f,g,h
i,j,k,l,m,.,.,.,.
i,j,k,l,m



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to