However, if I actually type the tabs, it doesn't work:
require 'csv'
str =<<"END_OF_STRING";
cow pig
hello "hello world" world
END_OF_STRING
CSV.parse(DATA, :col_sep => "\t") do |row|
p row
end
--output:--
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1895:in
`block (2 levels) in shift': Illegal quoting on line 1.
(CSV::MalformedCSVError)
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1863:in
`each'
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1863:in
`block in shift'
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1825:in
`loop'
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1825:in
`shift'
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1767:in
`each'
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1370:in
`parse'
from ruby.rb:8:in `<main>'
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
···
2011/8/18 Gagan Shah <gagannagpur@gmail.com>:
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