Split Files at Patterns With csplit

Cut a document into one file per section marker.

LinuxFilestextcliLow risk
Run csplit file '/^---$/' '{*}' to split at every line matching the separator.

01Command

Command
$ csplit report.txt '/^---$/' '{*}'

02What it does

csplit divides a file at regex or line-number boundaries and names the pieces automatically, which is far more precise than splitting by size when sections are delimited by markers. It is useful for parsing generated reports and logs into chunks.

03Risk

RiskLow risk
RequirementsPreinstalled on Linux (GNU coreutils)
!Warning: The pattern is a regex and consumes the delimiter line; check the resulting pieces before relying on their contents.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer

06Related solutions