Let’s say you have a single file (a mysql dump) containing the output of multiple database backups… and you want to split them out into individual files.
Input fil:
# MySQL dump 7.1
#
# Host: localhost Database: Purchase_Tracking
#
… Lots of CREATE TABLE and INSERTS …
# MySQL dump 7.1
#
# Host: localhost Database: Test
#
… Lots of CREATE TABLE and INSERTS …
Use the following csplit command to break the files up, based on the presence of the # Host: localhost line…
$ csplit -f db inputfile.dmp ‘/# Host: localhost/’ {*}
The above will create a series of files named db00, db01, db02, etc. for as many files as necessary.