From: 7stud -- Date: 2011-08-18T16:10:48+09:00 Subject: Re: Problem in reading txt file, by using CSV This works for me: require 'csv' str =<<"END_OF_STRING"; cow\tpig hello\t"hello\tworld"\tworld END_OF_STRING CSV.parse(str, :col_sep => "\t") do |row| p row end --output:-- ["cow", "pig"] ["hello", "hello\tworld", "world"] 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 `
' -- Posted via http://www.ruby-forum.com/.