csplit

v0.0.26
csplit [OPTION]... FILE PATTERN...

Split a file into sections determined by context lines

Options

--suffix-format=<FORMAT>, -b <FORMAT>

use sprintf FORMAT instead of %02d

--prefix=<PREFIX>, -f <PREFIX>

use PREFIX instead of 'xx'

--keep-files, -k

do not remove output files on errors

--suppress-matched

suppress the lines matching PATTERN

--digits=<DIGITS>, -n <DIGITS>

use specified number of digits instead of 2

--quiet, --silent, -s

do not print counts of output file sizes

--elide-empty-files, -z

remove empty output files

Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.

Examples

Split a file at lines 5 and 23:

csplit {{path/to/file}} 5 23

Split a file every 5 lines (this will fail if the total number of lines is not divisible by 5):

csplit {{path/to/file}} 5 {*}

Split a file every 5 lines, ignoring exact-division error:

csplit -k {{path/to/file}} 5 {*}

Split a file at line 5 and use a custom prefix for the output files:

csplit {{path/to/file}} 5 -f {{prefix}}

Split a file at a line matching a regular expression:

csplit {{path/to/file}} /{{regular_expression}}/

The examples are provided by the tldr-pages project under the CC BY 4.0 License.

Please note that, as uutils is a work in progress, some examples might fail.