Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Splitting MySQL dump


Rob,

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)


#!/usr/bin/perl
$i=0;
$base="dump_";
while(<>) {
 if (/^CREATE TABLE `(\S+)`/) {
    if (FO) {close FO}
    $i++;
    $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

dump_gmailinvites_1
dump_guestbook_2
dump_guestbook_auth_3


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



Regards, Martin