Created
February 11, 2015 19:38
-
-
Save honorelsu/5973ad7fb968fd7950c6 to your computer and use it in GitHub Desktop.
This file contains 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
require 'CSV' | |
input_path = ARGV[0] | |
output_path = ARGV[1] | |
output_array = Array.new | |
regex = /^([a-zA-Z]*).*$/ | |
#class | |
class OutputRow | |
attr_accessor :dcs_tags | |
def csv_row | |
#Put strings in order they should appear in the csv | |
[self.dcs_tags] | |
end | |
end | |
#input | |
CSV.foreach(input_path, headers: true, encoding: 'ISO-8859-1') do |row| | |
ro = OutputRow.new | |
ro.dcs_tags = row["NAME"].scan(regex).to_s | |
output_array << ro | |
end | |
#output | |
CSV.open(output_path, "w") do |output_csv| | |
#column headers for output csv | |
headers = ["NAME"] | |
output_csv << headers | |
output_array.each do |output_row| | |
output_csv << output_row.csv_row | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment