Skip to content

Instantly share code, notes, and snippets.

@deepakmahakale
Created July 5, 2018 05:18
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 deepakmahakale/9ba7a2e989779d7b767b78a0d5f84ac9 to your computer and use it in GitHub Desktop.
Save deepakmahakale/9ba7a2e989779d7b767b78a0d5f84ac9 to your computer and use it in GitHub Desktop.
require 'csv'
input_file = "#{Rails.root}/High School Database CSV.csv"
file_1 = CSV.open("#{Rails.root}/High_School_Database_#{1}.csv", 'w')
file_2 = CSV.open("#{Rails.root}/High_School_Database_#{2}.csv", 'w')
file_3 = CSV.open("#{Rails.root}/High_School_Database_#{3}.csv", 'w')
count = 0
CSV.foreach(input_file) do |row|
if count < 400000
file_1 << row
elsif count < 800000
file_2 << row
else
file_3 << row
end
count +=1
end
file_1.close
file_2.close
file_3.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment