Created
August 28, 2009 15:03
-
-
Save supriya/177020 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#the contents are not formatted correctly. This is a row from the current file: | |
#"006887148,5,21082009" | |
#It should not contain quotations and the effective date should be in MM/dd/YYYY format. | |
#006887148,5,08/21/2009 | |
#A few gottchas: | |
#Amount should not have dollar signs or commas – 2245.33 | |
#Integer value for amount is fine “5” will be processed as 5.00 dollars | |
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'fileutils' | |
csv_data = [] | |
arr = Array.new | |
input_file= File.open("input.csv", "r") | |
input_file.each_line { |line| | |
csv_data = line.split(',') | |
csv_data[1].tr_s("$","").split | |
csv_data[1].tr_s(",","").split | |
csv_data[2] = csv_data[2].match(/^(\d{2})(\d{2})(\d{4})$/) | |
csv_data[2] = "#{csv_data[2][2]}/#{csv_data[2][1]}/#{csv_data[2][3]}" | |
arr.push(csv_data) | |
} | |
output_file = File.open("output.csv", "w") do |csv| | |
csv << arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment