Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Separate file into context-based sections and place sections in files named xx00 through xxn (n < 100), breaking file at each pattern specified in arguments. See also split.
Options
-
Read from standard input.
-bsuffix, --suffix-format=suffix
Append suffix to output filename. This option causes -n to be ignored. suffix must specify how to convert the binary integer to readable form by including one of the following: %d, %i, %u, %o, %x, or %X. The value of suffix determines the format for numbers as follows:
%d
Signed decimal.
%i
Same as %d.
%u
Unsigned decimal.
%o
Octal.
%x
Hexadecimal.
%X
Same as %x.
-fprefix, --prefix=prefix
Name new files prefix00 through prefixn (default is xx00 through xxn).
-k, --keep-files
Keep newly created files even when an error occurs (which would normally remove these files). This is useful when you need to specify an arbitrarily large repeat argument, {n}, and you don't want an out-of-range error to cause removal of the new files.
-nnum, --digits=num
Use output filenames with numbers num digits long. The default is 2.
-s, -q, --silent, --quiet
Suppress all character counts.
-z, --elide-empty-files
Do not create empty output files. However, number as if those files had been created.
Arguments
Any one or a combination of the following expressions may be specified as arguments. Arguments containing blanks or other special characters should be surrounded by single quotes.
/expr/[offset]
Create file from the current line up to the line containing the regular expression expr. offset should be of the form +n or -n, where n is the number of lines below or above expr.
%expr%[offset]
Same as /expr/, except no file is created for lines previous to line containing expr.
num
Create file from current line up to (but not including) line number num. When followed by a repeat count (number inside { }), put the next num lines of input into another output file.
{n}
Repeat argument n times. May follow any of the preceding arguments. Files will split at instances of expr or in blocks of num lines. If * is given instead of n, repeat argument until input is exhausted.
Examples
Create up to 20 chapter files from the file novel:
csplit -k -f chap. novel '/CHAPTER/' '{20}'
Create up to 100 address files (xx00 through xx99), each four lines long, from a database named address_list: