I've recently received a SQL-dump file, but it contains multiple databases in it. Is there any tool I can use to easily split this up into multiple .sql files, one per database?
Presuming that this is a plaintext
.sql file with
CREATE SCHEMA or
CREATE DATABASE statements, you can effectively do this with
$ split -p 'CREATE DATABASE' bigfile.sql splitsql_
This will create a set of new files, e. g.
splitsql_ab, and so forth, wherein each file will start with the found
NAME split -- split a file into pieces [...] -p pattern The file is split whenever an input line matches pattern, which is interpreted as an extended regular expression. The matching line will be the first line of the next output file. This option is incompatible with the -b and -l options.