csplit

NAME

csplit - split files based on context information

SYNOPSIS

csplit [-ks] [-f prefix] [-n number] file arg1 ...argn

DESCRIPTION

The csplit(1) utility breaks the specified file into smaller files, as directed by the argn arguments. The argn arguments specify a context for where the file is to be split. If file is -, csplit(1) reads standard input.

OPTIONS

-f prefix
Name the created files prefix00, prefix01, and so on to prefixnn. The default prefix is xx. If the prefix would make the resulting file name longer than {NAME_MAX}, csplit(1) exits with a diagnostic message and no files are created.
-k arg
Leave any previously created files intact if an error occurs. Otherwise, csplit(1) removes them.
-n number
Use number decimal digits to form file names for the file pieces. The default is 2. If the number of digits, combined with the prefix, would make the resulting file name longer than {NAME_MAX}, csplit(1) exits with a diagnostic message and no files are created.
-q
Suppress the writing of file size messages to standard output. A synonym for -s.
-s
Suppress the writing of file size messages to standard output.

The arguments arg1 through argn specify where to split the file. They can be a combination of the following:

/rexp/[+|-offset]
Create a file using the current line up to but not including the first line that matches the basic regular expression rexp plus an optional offset. The offset is a positive integer preceded by + (for a number of lines after the regular expression match) or - (for a number of lines before the regular expression match). That boundary, the regular expression match plus the offset (if any), becomes the new current line.
%rexp%[+|-offset]
Skip from the current line up to but not including the first line that matches the basic regular expression rexp plus an optional offset. This behaves in the same way as /rexp/, except that it doesn't create a file.
line_num
Create a file from the current line, up to but not including line number line_num. The first line is numbered 1, and the line line_num becomes the new current line.
{num}
Repeat previous operand num times.

It is always an error if the argument does not match; csplit(1) fails.

DIAGNOSTICS

If the file is split successfully, csplit(1) exits with status 0. Otherwise, it exits with a status of >0.

SEE ALSO

sed(1)

split(1)