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



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
.



Relevant Pages

  • How to remove trailing commas and points from a CSV file ?
    ... Please forgive my lack of Perl credentials, but i am a complete beginner ... I have a CSV file, which comes in the following format: ... how could I get rid of the trailing points and commas, ...
    (perl.beginners)
  • Re: How to remove trailing commas and points from a CSV file ?
    ... how could I get rid of the trailing points and commas, ... the output CSV file could get following neat format (without the ...
    (perl.beginners)
  • Re: Array size limit in Perl
    ... The data format is as follows, ... And my perl code is as follows. ... Have you tried printing this string rather than just executing it, ... examine the sorted array. ...
    (perl.beginners)
  • Re: Using References to Formats, Examining Scalars With Devel::Peek
    ... the format to be able to refer to it by another name didn't occur to me. ... Seems most of the fields are the same as for the rest of the Perl ... from integer to double and how frequently the string portions are updated. ... Using an operator or a built-in with a double and an int usually converts ...
    (comp.lang.perl.misc)
  • Re: Implementing Storables STORABLE_freeze and STORABLE_thaw
    ... > Hello Perl People, ... > I'm interested in cloning some Perl objects that I've written, ... Whichever format conveys the necessary information to let you unfreeze ... and put whatever I needed for serialization into the list of refs that ...
    (comp.lang.perl.misc)