-
-
Save criscokid/f8c0c36bda02f32aa2a6 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 | |
matches = regex.match(row["NAME"]) | |
ro.dcs_tags = matches[1] #could also do this as ro.dcs_tags = $1 | |
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