Posted On 2007-04-27 by FortyPoundHead
Keywords: Command Reference
Tags: Linux Commandline Linux
Views: 1501

Split a file into context-determined pieces.

csplit [options]... INPUT PATTERN...

Creates zero or more output files containing sections of
INPUT (standard input if INPUT is `-'').

The contents of the output files are determined by the PATTERN
arguments, as detailed below. An error occurs if a PATTERN argument
refers to a nonexistent line of the input file (e.g., if no remaining
line matches a given regular expression). After every PATTERN has been
matched, any remaining input is copied into one last output file.

By default, `csplit'' prints the number of bytes written to each
output file after it has been created.

The types of pattern arguments are:

Create an output file containing the input up to but not including
line N (a positive integer). If followed by a repeat count, also
create an output file containing the next LINE lines of the input
file once for each repeat.

Create an output file containing the current line up to (but not
including) the next line of the input file that contains a match
for REGEXP. The optional OFFSET is a `+'' or `-'' followed by a
positive integer. If it is given, the input up to the matching
line plus or minus OFFSET is put into the output file, and the
line after that begins the next section of input.

Like the previous type, except that it does not create an output
file, so that section of the input file is effectively ignored.

Repeat the previous pattern REPEAT-COUNT additional times.
REPEAT-COUNT can either be a positive integer or an asterisk,
meaning repeat as many times as necessary until the input is

The output files'' names consist of a prefix (`xx'' by default)
followed by a suffix. By default, the suffix is an ascending sequence
of two-digit decimal numbers from `00'' and up to `99''. In any case,
concatenating the output files in sorted order by filename produces the
original input file.

By default, if `csplit'' encounters an error or receives a hangup,
interrupt, quit, or terminate signal, it removes any output files that
it has created so far before it exits.

The program accepts the following options.

`-f PREFIX''
Use PREFIX as the output file name prefix.

`-b SUFFIX''
Use SUFFIX as the output file name suffix. When this option is
specified, the suffix string must include exactly one
`printf(3)''-style conversion specification, possibly including
format specification flags, a field width, a precision
specifications, or all of these kinds of modifiers. The format
letter must convert a binary integer argument to readable form;
thus, only `d'', `i'', `u'', `o'', `x'', and `X'' conversions are
allowed. The entire SUFFIX is given (with the current output file
number) to `sprintf(3)'' to form the file name suffixes for each of
the individual output files in turn. If this option is used, the
`--digits'' option is ignored.

`-n DIGITS''
Use output file names containing numbers that are DIGITS digits
long instead of the default 2.

Do not remove output files when errors are encountered.

Suppress the generation of zero-length output files. (In cases
where the section delimiters of the input file are supposed to
mark the first lines of each of the sections, the first output
file will generally be a zero-length file unless you use this
option.) The output file sequence numbers always run
consecutively starting from 0, even when this option is specified.

Do not print counts of output file sizes.

About the Author

FortyPoundHead has posted a total of 1974 articles.


Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Recent Forum Posts

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers

New security implemented
dwirch posted on August 8, 2017 at about 6:43 in Site News

New security implemented
dwirch posted on July 23, 2017 at about 6:58 in Site News

Fold Code Manager into main KB?
VB6Boy posted on July 22, 2017 at about 14:42 in Site News

Fold Code Manager into main KB?
dwirch posted on July 22, 2017 at about 14:41 in Site News