csplit - context split


Environment Variables
See Also


csplit [-s] [-k] [-f prefix] [-n digits] file args ...


Csplit reads file and writes it in pieces as specified by the further operands args. The destination file names have the form xx00, xx01, and so on by default.

The args operands can have one of the following forms:
/rexp/[[+|-]offset] Write text between the current line and the next line matching the regular expression rexp to an output file piece. If offset is also specified, writing ends offset lines below the matching line for positive values, or above the matching line for negative ones. The text section written to the next file piece starts at the matching line with offsetapplied; thus repeated matches with negative offsets will repeatedly write the same text part. With /usr/5bin/csplit, rexp is treated as a simple regular expression, whereas /usr/5bin/s42/csplit, /usr/5bin/posix/csplit, and /usr/5bin/posix2001/csplit treat it as a basic regular expression (see ed(1). Backslash escapes a literal '/' in the expression.
%rexp%[[+|-]offset] Also match rexp as described above, but skip the text between the current line and the matching one (plus offset) instead of writing it. Backslash escapes '%'.
number Create a piece of the file for the text between the current line and line number. Line numbering starts at 1.
{repetition} Apply the previous argument additionally repetition times if it searches for a regular expression. If it specifies a line number, include the text between the current line and the current line plus the line count given in the argument, and repeat this process repetition times.

The following options can be used with csplit:
-f prefix Use the given prefix as the first part of the file names created (instead of xx).
-n digits Use digits positions for the second part of the file names created, instead of the default 2. This allows for the creation of more than 100 file pieces. This option was introduced by POSIX.2.
-k When csplit detects an error (as an argument that does not correspond to a part of the input file) or it is interrupted from the terminal, output files already created will be deleted. Specifying this option causes csplit to keep these files.
-s The number of bytes written to each file piece is normally written to standard output; this option inhibits these statistics.


Create individual files section00, section01 ... for each section of a troff -ms document:

csplit -k -f section doc.ms '/^.[NS]H/' {100}


  See locale(7).
  Affects the collation order for range expressions, equivalence classes, and collation symbols in basic regular expressions.
  Determines the mapping of bytes to characters, the set of word boundary characters and the composition of character classes in basic regular expressions.


ed(1), split(1)

Heirloom Toolchest CSPLIT (1) 8/14/05
Generated by a modified version of manServer 1.07 from csplit.1 using man macros.