Updated: April 19, 2023

Split a file based on the context (POSIX)


csplit [-ks] [-f prefix] [-n digits] file arg1 [... argn]

Runs on:

QNX Neutrino


-f prefix
Use prefix instead of xx to name the output files (i.e., name the created files prefix00, prefix01, ..., prefixn instead of xx00, ..., xxn).
Leave previously created files intact. By default, csplit removes created files if an error occurs.
-n digits
The number of digits to append to the prefix. The default is 2.
Suppress the output of file size messages.


The csplit utility splits a file into n + 1 sections, as prescribed by arg1...argn, and then displays the size of the output files.

Each argument specifies where a section ends as follows:

Copy lines until the next line matches the regular expression, rexp. A positive or negative relno specifies a relative line number from the match.
Same as above, except the lines are discarded instead.
Copy nlines lines from the file.
Repeat the preceding argument this number of times.


Extract a file that's encoded with uuencode:

csplit mail '%^begin%' '/^end/+1' '%.*%'

Split a file into three parts of 1, 10, and 100 lines:

csplit file 1 10 100

Exit status:

An error occurred.