AKa*_*pun 0 ruby windows csv rubygems eol
For some reason CSV gem is generating CSVs with Unix EOL (see screenshot) here: https://www.dropbox.com/s/4re7tpp4pj9psov/ice_screenshot_20171230-162304.png?dl=0 Screenshot made in Notepad++ (View all Characters)
Code I use:
require 'csv'
all_the_things = []
all_the_things << ["item1.1","item1.2","item1.3"]
all_the_things << ["item2.1","item2.1","item2.1"]
all_the_things << ["item3.1","item3.1","item3.1"]
CSV.open("test.csv", "wb" ) do |row|
row << ["Column1", "Column2", "Column3"] #just headers
all_the_things.each do |data|
row << data
end
end
Run Code Online (Sandbox Code Playgroud)
Is there a way to make it use Windows EOL (CR LF) instead of UNIX (LF) ones ?
I'm using Windows 10, and if I just output some lines to file using puts everything working just fine (albeight managing proper data structure without CSV gem is nightmare):
....
File.open("test.csv", "w") do |line|
myarray.each do |data|
line.puts data
end
end
Run Code Online (Sandbox Code Playgroud)
Thank you in advance for any ideas and Happy New Year !
As it is clearly stated in the documentation, one might use the row_sep option to specify the row separator:
require 'csv'
# ??????????????? here
CSV.open("/tmp/file.csv", "wb", row_sep: "\r\n") do |csv|
csv << %w|1 2 3 4|
csv << %w|a b c d|
end
Run Code Online (Sandbox Code Playgroud)
Also, there is no “CSV gem,” it’s ruby standard library.