Skip to content

Instantly share code, notes, and snippets.

@rochefort
Created July 7, 2011 22:45
Show Gist options
  • Select an option

  • Save rochefort/1070725 to your computer and use it in GitHub Desktop.

Select an option

Save rochefort/1070725 to your computer and use it in GitHub Desktop.
split_file.rb
#!/usr/bin/ruby
file = 'test.txt'
split_line_size = 3
file_cnt = 0
out = open('dummy.txt', 'w')
open(file).each_with_index do |line, i|
if i % split_line_size == 0
out.close unless out.closed?
out = open("split#{file_cnt}.txt", 'w')
file_cnt += 1
end
out.write line
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment