With Ruby, how to import a CSV file that has a row that is missing a value in the last column, and thus ends with a comma? -


i'm using ruby import csv file, , things seem working okay, except fact 1 of rows ends in comma, due last column having missing value.

i'm using ruby's native csv library, call:

   csv.open(file, :col_sep => ",") 

and getting csv::malformedcsverror: unquoted fields not allow \r or \n (line 10),

and if add :row_sep call,

csv.open(file, :col_sep => "," , :row_sep => "\r\n") 

, , getting csv::malformedcsverror: unquoted fields not allow \r or \n (line 1).

your line endings not \r\n then.

you can try using :row_sep => :auto (it'll different eols).

if csv file not supposed contain fields multiple lines i'll advice clean whole thing e.g. file.gsub(/\r\r?\n?/, "\n"), , use simple "\n" row_sep.

see https://stackoverflow.com/a/18969935/4640187


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -