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



Hi dear Jeff:

Thank you very much for your help

Yiur script is working flawlessly

Just another question:

How could I re-write your script in order to treat the __DATA__
portion of your code as an external file ?

I happen to have the whole CSV file and I would not want to mix
directly with it, but to reference it from the perl code

How could I accomplish that ?

Should I substitue the <DATA> for the name of the CSV file in the perl code ?

Thank you very much for any help

Regards

Erasmo

On 26/06/2008, Jeff Peng <peng.kyo@xxxxxxxxx> wrote:
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

  • Re: How do I allow blank columns in a .CSV file?
    ... I am using the csv file to upload data from excel to a website - the website ... "Dave Peterson" wrote: ... not buying much by making sure that there are extra commas in the file. ...
    (microsoft.public.excel.misc)
  • Re: Creating CSV Comma Delimited File
    ... You may be able to eliminate the lines with just commas on it by resetting the ... new workbook as a .csv file. ... don't care about those extra columns. ... MsgBox "Upload File Saved for TECHNICIANS" ...
    (microsoft.public.excel.misc)
  • Re: Parsing large CSV data file.
    ... I have a 180MB csv file. ... My objective is to find how many of those 2 char. ... the 'commas' and 'numbers' from the row before doing this... ... whole loop looks like, ...
    (comp.soft-sys.matlab)
  • Re: How to import a large list of contacts?
    ... > may be possible to export the Excel file as a CSV file that will be almost ... > example of the text with commas in the CSV file. ... > aka Kuay Tim ... > I've got an excel file with about 40 e-mail address's. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Opening then saving a CSV file looses Commas in Excel 2003
    ... This might describe the problem of too many commas in CSV files: ... Column Delimiters Missing in Spreadsheet Saved as Text ... > I've included a sample CSV file that exibits this particular behavior. ...
    (microsoft.public.excel)