 |
Forums |
Admin Discussion Forums: help Start New Thread
By: James Gray
RE: Parsing malformed CSV file [ reply ] 2008-02-06 04:37
|
FasterCSV will not help with malfromed CSV, no. The strictness to its parser is one of the reasons it is so fast.
It seems for this case a simple `split(",")` might be all you need though.
Hope that helps.
James Edward Gray II
|
By: Alexander Logvinov
Parsing malformed CSV file [ reply ] 2008-02-06 03:15
|
Is there a chance to read this file?
Unfortunally this file is not composed by me and I'm not able to change it's format.
# cat 1.csv
"11111","2222","3333 444"3434","555"
# cat csvtest.rb
require 'rubygems'
require 'faster_csv'
contents = File.open('1.csv').read
FasterCSV.parse(contents) do |row|
puts row
end
]# ruby csvtest.rb
/usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1592:in `shift': Unclosed quoted field on line 1. (FasterCSV::MalformedCSVError)
from /usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1512:in `loop'
from /usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1512:in `shift'
from /usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1457:in `each'
from /usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/faster_csv.rb:1205:in `parse'
from csvtest.rb:5
|
|
 |