Skip to content

Instantly share code, notes, and snippets.

@jhbabon
Created February 14, 2013 16:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jhbabon/4954027 to your computer and use it in GitHub Desktop.
Save jhbabon/4954027 to your computer and use it in GitHub Desktop.
Clean all INSERT command from a mysql dump with grep and ruby
#!/usr/bin/env ruby
# @see http://stackoverflow.com/a/11522507
if ARGV.empty?
$stdout.puts "Usage: cleanup.rb dump.sql table_a [table_b ...]"
else
args = ARGV.reverse
file = args.pop
pattern = "-E \"INSERT INTO \\`(#{args.join('|')})\\\`\""
`grep -v #{pattern} #{file} > cleanup.sql`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment