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

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

Need a robust off the grid power solution?

Off the grid, portable power solution for your devices - big and small

Check out the Goal Zero Yeti line of power solutions - powerful Li-Ion batteries that you can charge from Solar Panels or via wall charger.  These are the ultimate in portable electric power!