csplit: split, but with a little more control

Remember lxsplit? I mentioned GNU split when I brought it up back in May. split is good stuff — breaks apart a file based on size or count, and you can reattach it with cat.

But what if you don’t care about the size, but want to break files depending on the contents?

That’s where csplit comes in.


Another goodie from coreutils, csplit skims through the contents of a file, looks for matching strings, and where it finds it, breaks the file apart.

In the screenshot above, csplit is skimming through (yet another) file of random words, and breaking every time it finds the letter x … as many times as it takes. Cool, huh?

csplit is marvelously flexible; you can give it patterns, repeat those patterns, control the output filenames, numbering system … you name it.

csplit is really worth investigating. split on its own is a great tool, but csplit gives the same effect, with a little more control. 🙂