From: "Bartosz DziewoƄski" Date: 2011-08-18T18:35:53+09:00 Subject: Re: Problem in reading txt file, by using CSV 2011/8/18 Gagan Shah : > I have switched my apps to Rails-3.0.2 & Ruby-1.9.2. I am reading .txt > file with tab separated. In the file, there is row like this, > > [APPLE US USTR80302299 "Elmer Bernstein Sweet Smell of Success" > Mainstream Records USTR80302299] > > Due to the double quotes in one of the column ("Elmer Bernstein Sweet > Smell of Success"), its generating error of :- Unclosed quoted field > > > @parsed_file = > CSV.open("#{RAILS_ROOT}/private/sales_report_files/#{@file_folder}/#{@sub_file_folder}/#{@file_name.filename}",'r') You're not setting the :col_sep option, so CSV assumes the separator is a comma (while in the file it's clearly a space). It worked for me: irb(main):004:0> CSV.open('data.txt', col_sep:' ').read => [["APPLE", "US", "USTR80302299", "Elmer Bernstein Sweet Smell of Success", "Mainstream", "Records", "USTR80302299"]] The error you got is quite cryptic, but it makes sense: you had a single column, which contained quotes not at the beginning or end - CSV parser considers this incorrect. -- Matma Rex