Split Files at Patterns With csplit
Cut a document into one file per section marker.
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
!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
- csplit.1.en.html manual page (Debian bookworm)Evidence: Documents csplit, which splits files at line numbers or patterns.
Last verified: 2026-10-13 · Category: Developer
06Related solutions
Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Extract a .tar.gz archive with tar
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Check free disk space on each filesystem with df
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.