in reply to splitting cvs file without line breaks
This should work for a variable number of fields provided that:
#! perl -slw use strict; my $data = do{ local $/; <DATA> }; my $noOfFieldsMinus1 = 5; my @records = $data =~ m[ ( (?: (?: "[^"]+" ##" | [^,]+ ) , ){$noOfFieldsMinus1} (?: "[^"]+" ##" | \S+ ) ) \s+ ]gx; print for @records; __DATA__ "Business Date","Location Name","Revenue Center Name","Tender Count"," +Tender Name","Tender Total" 2007-05-14 00:00:00.0,"Aville","x",300,"b +",6899 2007-05-14 00:00:00.0,"Aville","x",6,"c",198.50 2007-05-14 00: +00:00.0,"Aville","b",290,"Cash",12336.10 2007-05-14 00:00:00.0,"Bvill +e","c",14,"d",958.40
Produces:
C:\test>615576 "Business Date","Location Name","Revenue Center Name","Tender Count"," +Tender Name","Tender Total" 2007-05-14 00:00:00.0,"Aville","x",300,"b",6899 2007-05-14 00:00:00.0,"Aville","x",6,"c",198.50 2007-05-14 00:00:00.0,"Aville","b",290,"Cash",12336.10 2007-05-14 00:00:00.0,"Bville","c",14,"d",958.40
Subsequent treatment of the csvs by any of the usual mechanisms.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: splitting cvs file without line breaks
by rendier (Initiate) on May 15, 2007 at 21:06 UTC |