Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Splitting MySQL dump


Not sure about the csplit seg fault (never used it to be honest)

Anyway here is a Perl script that works (as far as my limited testing allowed)

while(<>) {
 if (/^CREATE TABLE `(\S+)`/) {
    if (FO) {close FO}
    $fn = "${base}${1}_${i}";
    open FO,">","$fn" or die "Could not open $fn";
    print "Writing $fn:",$_;
 print FO $_;

use it as "perl csplit.pl <sqlfile.sql"

you will end up with files like


(The increments on the file name are probably superfluous, but it
makes sure the filename don't collide)

Regards, Martin