Created
December 23, 2014 21:19
-
-
Save DavidLGoldberg/3bc09209de5abbdbd2a0 to your computer and use it in GitHub Desktop.
Some dirty CSV parsing I'll probably never need
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
#!/usr/bin/env ruby | |
# This script translates Christy's Company's investors to all companies by investors. | |
# INPUT: arg0 as a path to a csv | |
# OUTPUT: arg1 as a path to a csv | |
require 'CSV' | |
investors = {} | |
CSV.foreach(ARGV[0], {headers: false}) do |row| | |
company = row[0] | |
row[1,row.length].each do |investor| | |
investors[investor] ||= [] | |
investors[investor].push company unless investor.nil? or investor.empty? | |
end | |
end | |
CSV.open(ARGV[1], "wb") do |csv| | |
investors.each do |key, value| | |
csv << ([key] + [value]).push(value.length) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment