CSPLIT(1V) — UNIX Programmer’s Manual
NAME
csplit − context split
SYNOPSIS
/usr/5bin/csplit [ −k ] [ −s ] [ −f prefix ] file arg1 [ arg2 ... argn ]
DESCRIPTION
csplit reads file and splits it into consecutive sections as defined by the arguments arg1 through argn. The sections are written to separate files, named by the prefix (default xx) with the numbers 00 to n appended. These files will contain the following lines from file:
xx00: From the start of the file up to (but not including) the line referenced by arg1.
xx01: From the line referenced by arg1 up to (but not including) the line referenced by arg2.
...
xxn: From the line referenced by argn to the end of the file.
Csplit accepts the following options:
−s Suppress output of character counts for each output file.
-k Do not remove output files if an error occurs.
-f prefix Use specified prefix instead of xx.
A file argument of − makes csplit read its standard input.
The position arguments arg1 through argn may be any of the following:
/regexp/ Addresses the range from the current line up to (but not including) the line containing the regular expression regexp. The regular expressions used are in the style of ed(1). An optional + or - sign may be used to apply a positive or negative offset to the matching line − for example, /main/-1.
Regular expressions should be protected against expansion by the shell, and may not contain newlines.
%regexp%
As above, but the section is skipped and no output file is produced.
lineno Addresses the range from the current line up to (but not including) the numbered line.
{num} Repeat count. This may follow any of the above arguments. When applied to a regular expression argument, the argument is applied num more times. If it follows a line number argument, the file will be split num times every lineno lines.
EXAMPLES
The following command splits the standard input after the first blank line, writing two files, xx00 and xx01:
csplit - ’/^$/’
This example splits the file into 4 50-line pieces:-
csplit file 50 {3}
SEE ALSO
DIAGNOSTICS
The message "arg − out of range" means that the given argument does not refer to a line between the current line and the end of the file.
BUGS
Do not confuse csplit(1V) with csplit(1) which splits a file into chunks of a fixed number of characters.
4th Berkeley Distribution