Update a CSV file : csv « Development « Ruby
- Ruby
- Development
- csv
Update a CSV file
require 'csv'
File.open("newdata.csv","w") do |file|
IO.foreach("data.csv") do |line|
a=CSV::parse line.chomp
if a[1].to_i > 20
s=a[2].to_i
a[2]=s*1.1 # 10% raise
end
file.puts CSV::create(a)
end
end
Related examples in the same category