Created
September 23, 2013 09:14
-
-
Save bartlomiejdanek/6668216 to your computer and use it in GitHub Desktop.
split your csv files
This file contains hidden or 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' | |
infile = ARGV[0] | |
slice = ARGV[1] || 100 | |
origin = CSV.open infile | |
all_lines = origin.readlines | |
header = all_lines.first | |
all_lines.delete_at(0) | |
all_lines.each_slice(slice).each_with_index do |lines, idx| | |
CSV.open("splitted_#{idx}.csv", 'w') do |csv| | |
csv << header | |
lines.each do |line| | |
csv << line | |
end | |
end | |
end | |
# $ ruby splitter.rb file.csv 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment