Skip to content

Instantly share code, notes, and snippets.

@DavidLGoldberg
Created December 23, 2014 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidLGoldberg/3bc09209de5abbdbd2a0 to your computer and use it in GitHub Desktop.
Save DavidLGoldberg/3bc09209de5abbdbd2a0 to your computer and use it in GitHub Desktop.
Some dirty CSV parsing I'll probably never need
#!/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