Ruby CSV: How can I read a tab-delimited file?, "r").each do |row|
  puts row


And I am getting the following error:

CSV::MalformedCSVError Unquoted fields do not allow \r or \n 


The file name is a tab-delimited .txt file. I did it specifically. I have. CSV file, I went to excel and saved the file as a .txt tab. Thus, tabs are limited.


read tab-delimited files?


source to share

2 answers

Try specifying a field separator like this:"name", "r", { :col_sep => "\t" }).each do |row|
  puts row


And memorize require 'csv'

and read the DOCS



By default it CSV

uses a comma as a separator, this is because CSV stands for "comma separated values".

If you want a different separator (in this case, tabs), you need to make it explicit.

Example :

p"aaa\tbbb\tccc\nddd\teee", col_sep: "\t").read


Relevant documentation:



All Articles