Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

csplit

v(uutils coreutils) 0.8.0
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, -q, -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 in two parts, starting the second one at line 10:

csplit {{path/to/file}} 10

Split a file in three parts, starting the latter parts in lines 7 and 23:

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

Start a new part at every 5th line (will fail if number of lines is not divisible by 5):

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

Start a new part at every 5th line, ignoring exact-division error:

csplit {{[-k|--keep-files]}} {{path/to/file}} 5 {*}

Split a file above line 5 and use a custom prefix for the output files (default is xx):

csplit {{path/to/file}} 5 {{[-f|--prefix]}} {{prefix}}

Split a file above the first line matching a regex pattern:

csplit {{path/to/file}} /{{regex}}/

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.