Split a Markdown File by Its Headings

Today I learned about an ingenious tool called csplit on the Zettelkasten Forums. It’s available on macOS and Linux. You can use it to split a single Markdown file into multiple files, one for each chapter or section.

The invocation that @mediapathic uses to split his manuscript at the level-2-headings in the original Markdown manuscript is this:

gcsplit --prefix='novelname' --suffix-format='%03d.md'  novel-file.md /##/ "{*}"

The macOS csplit program apparently behaves a bit differently so you’d need to install gcsplit via brew install coreutils first.