Skip to content

Instantly share code, notes, and snippets.

@thorvn
Created July 30, 2018 03:59
Show Gist options
  • Save thorvn/1cccfd2b97dd47b44732cf0d21d2ae56 to your computer and use it in GitHub Desktop.
Save thorvn/1cccfd2b97dd47b44732cf0d21d2ae56 to your computer and use it in GitHub Desktop.
Split big sql file
filename = 'flowdata_201803052230.sql'
INSERT_MATCHER = 'INSERT INTO'
file = 1
counter = 1
File.open(filename, 'r').each do |line|
next unless line.include? INSERT_MATCHER
File.open(file.to_s + '.sql', 'a+') { |file| file.write("\n" + line) }
counter += 1
if counter == 100
file += 1
counter = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment