- To: "Rob Sharp" <rob@xxxxxxxxxxx>
- Subject: Re: [SLUG] Splitting MySQL dump
- From: "Martin Visser" <martinvisser99@xxxxxxxxx>
- Date: Wed, 10 May 2006 22:31:14 +1000
- Cc: slug@xxxxxxxxxxx
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=C+s072Cp5q0mV/ALyR6c7kcVrp2deQW/jkzL2hiMEXoxnnGrgLeQy6Zx5gL48kMNn0p3Bnq4XJrbzzXq6r9jkIbQTzEUe32VhziCSTs/O4INMukcMh2iVHJKQB38c13xaauO9BKuCouh2BXPIC5ng3XUDkicHz1VAYRJ1w7MF54=
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