From: Robert Klemme Date: 2012-04-19T06:25:25+09:00 Subject: Re: Converting CSV On Wed, Apr 18, 2012 at 10:30 PM, Jan E. wrote: > cristian cristian wrote in post #1057250: >> Ok, thanks! Will this save the new file with the name "new_csv"? > > No, it will overwrite the original file. If you want to write the CSV to > a new file, change the code to > > File.open 'new.csv', 'w' do |csv| >  new_csv = File.read('old.csv').gsub(/[^\n\r;]+/, '"\0"').gsub(';', > ',') >  csv.print new_csv > end If the file is large this can easily break because you need to read the whole thing into memory. I'd also rather use the proper tool for the job instead of cooking something with regexp. In this case I'd do require 'csv' CSV.open("new.csv", "wb", col_sep: ",", force_quotes: true) do |csv_out| CSV.foreach("old.csv", col_sep: ";") do |rec| csv_out << rec end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/