csplit command

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.

About the author

Timothy Platt

I'm an all around computer junkie, interested in many aspects of programming, operating systems, and enterprise IT technologies. I love Mac OS X, Linux, and Windows and I'm not particularly militant about any one over the other.