csplit: Splitting a text file into individual files according to a certain pattern

Oct 4, 2021 14:15 · 58 words · 1 minute read

csplit --quiet --elide-empty-files restore-mail-dump.txt '<REGEX_PATTERN>' '{*}'

<REGEX_PATTERN> can e.g. be /^From:/ (e.g. when having a text file that consists of multiple emails). {*} stands for “Repeat this split forever (in constrast to e.g. just splitting the file for the first x times).

Learn more on the respective explainshell.com output.

Some more concrete examples for csplit usage: https://www.golinuxcloud.com/csplit-split-command-examples-linux-unix/#2_csplit_based_on_pattern_match