csplit command

Disclosure: Links to other sites may be affiliate links that generate us a small commission at no extra cost to you.

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

Tim

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 more!