Skip to content

Instantly share code, notes, and snippets.

@themasch
Created April 4, 2011 21:54
Show Gist options
  • Save themasch/902539 to your computer and use it in GitHub Desktop.
Save themasch/902539 to your computer and use it in GitHub Desktop.
simple shell script to translate a mysql database into a sqlite create script
#!/bin/sh
mysqldump --compact --compatible=ansi --default-character-set=binary -u ${1} -p ${2} |
grep -v ' KEY "' |
perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' |
perl -pe '
if (/^(INSERT.+?)\(/) {
$a=$1;
s/\\'\''/'\'\''/g;
s/\\n/\n/g;
s/\),\(/\);\n$a\(/g;
}
' | sed 's/unsigned //g' | sed 's/AUTO_INCREMENT//g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment