MySQL dump to tables

A very small GAWK script that splits a mysql text dump to separate table dump files.

#!/bin/sh
# GPLv2 by Erno Rigo <mcree_AT_tricon_DOT_hu>
 
gawk '
 BEGIN { FS=" "; dest="/dev/null" }
 /^(USE)/ { dir=gensub(";","","g",$2) ; dir=gensub("`","","g",dir) ; system("mkdir "dir) }
 /^(CREATE|USE|DROP)/ { fflush(dest); dest="/dev/null" }
 /^CREATE TABLE/ { file=gensub("`","","g",$3) ; fflush(dest); dest=dir"/"file".sql" }
 { print >> dest }
'