Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created May 14, 2013 19:47
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 danidiaz/5578909 to your computer and use it in GitHub Desktop.
Save danidiaz/5578909 to your computer and use it in GitHub Desktop.
Dividing a postgresql database dump.
currfile = nil
File.open("postgresql.dmp", "r") do |file_handle|
file_handle.each_line do |line|
if line =~ /^COPY (\S+) /
currfile.close unless currfile.nil?
currfile = File.open("./postgresql_parts/#{$1}.dmp","w")
end
currfile.puts(line) unless currfile.nil?
end
end
currfile.close unless currfile.nil?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment