Skip to content

Instantly share code, notes, and snippets.

@criscokid
Forked from honorelsu/tag.rb
Last active August 29, 2015 14:15
Show Gist options
  • Save criscokid/f8c0c36bda02f32aa2a6 to your computer and use it in GitHub Desktop.
Save criscokid/f8c0c36bda02f32aa2a6 to your computer and use it in GitHub Desktop.
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