Re: How to remove trailing commas and points from a CSV file ?
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Thu, 26 Jun 2008 14:53:01 -0700
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
.
- References:
- How to remove trailing commas and points from a CSV file ?
- From: Erasmo Perez
- How to remove trailing commas and points from a CSV file ?
- Prev by Date: Check if directory is empty on Win32
- Next by Date: Re: How to remove [], {}, and other characters, rendering numeric values in a CSV file ?
- Previous by thread: Re: How to remove trailing commas and points from a CSV file ?
- Next by thread: How can I translate it back to @ sign.
- Index(es):
Relevant Pages
|