Malformed CSV Error

Hello, I am getting error :- #<CSV::MalformedCSVError: Unclosed quoted field on line 1892.>.

I have following code :-

Unclosed quoted field on line means the line contans odd number of " or '

tom

Gagan Shah wrote in post #1014733:

I am getting error :- #<CSV::MalformedCSVError: Unclosed quoted field on line 1892.>.

@parsed_file =

CSV.open("#{RAILS_ROOT}/private/sales_report_files/#{@file_folder}/#{@sub_file_folder}/#{@file_name.filename}",'r',:col_sep

=>?\t)

I see that you're input file is tab separated, but you have not mentioned how strings are delimited in your file.

I have tried to escape row no.-1892 by using '@parsed_file.shift', but it didn't work. Please suggest, so I can skip the corrupted row.

Take note that some people (and unfortunately some frameworks) incorrectly attempt to escape quotes using the backslash character (\"). The proper way to delimit strings in CSV files is to surround them with double quotes (") where strings containing double quote characters should escape them using two consecutive double quotes.

Example:

This is WRONG: "A string containing a double quote \" character", "Another string",23

This is correct: "A string containing a double quote "" character", "Another string",23

See RFC 4180 - Common Format and MIME Type for Comma-Separated Values (CSV) Files for more information. Section 2.7 explains the above.