I have what I think is a really simple problem to solve (preferably with OS X / *nix terminal tools rather than windows command line).

I have a manuscript formatted in markdown with # (H1) denoting a chapter heading. I would like to break this large file up into smaller chapter files as I'll later be converting the manuscript to epub / mobi with pandoc. This separate-file-per-chapter format is the the recommended format according to the pandoc docs (http://johnmacfarlane.net/pandoc/epub.html ) and also makes the editing process a little less unwieldy. Interestingly it is similar to what some other projects have done e.g. https://github.com/visionmedia/masteringnode

I was thinking that this would be possible with a simple python script or using something like sed but I just don't know where to start. Any help would be great!


You're looking for the csplit tool.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.