'\"macro stdmacro
.if n .pH g1.csplit @(#)csplit	40.7 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} csplit 1 "Directory and File Management Utilities" "\&"
.if \nX=1 .ds x} csplit 1 "Directory and File Management Utilities"
.if \nX=2 .ds x} csplit 1 "" "\&"
.if \nX=3 .ds x} csplit "" "" "\&"
.TH \*(x}
.bd S B 3
.SH NAME
\f4csplit\f1 \- context split
.SH SYNOPSIS
\f4csplit\f1
\f1[\f4\-s\f1]
\f1[\f4\-k\f1]
\f1[\f4\-f\f1
.IR prefix ]
.I "file arg1"
[\|.\|.\|.
.IR argn ]
.SH DESCRIPTION
\f4csplit\fP
reads
.I file\^
and separates it into
.IR n +1
sections,
defined by the arguments
.IR arg1 "\|.\|.\|.\|" argn .
By default the sections are placed in
\f4xx00\f1\|.\|.\|.\|\f4xx\f2n\f1\f1
.RI ( n
may not be greater than 99).
These sections get the following pieces of
.IR file :
.RS 2
.TP 6
00:
From the start of
.I file\^
up to (but not including) the line referenced by
.IR arg1 .
.PD 0
.TP 6
01:
From the line referenced by
.I arg1\^
up to the line referenced by
.IR arg2 .
.sp -.5
.RS 6
\f4\&.\f1
.sp -.5
\f4\&.\f1
.sp -.5
\f4\&.\f1
.RE
.TP 6
\f2n\f1:
From the line referenced by
.I argn\^
to the end of
.IR file .
.PD
.RE
.PP
If the
.I file
argument is a
\f4\-\f1,
then standard input is used.
.PP
The options to
\f4csplit\fP
are:
.RS 2
.TP 10
\f4\-s\f1
\f4csplit\fP
normally prints the character counts for each file created.
If the 
\f4\-s\f1
option is present,
\f4csplit\fP
suppresses the printing of all character counts.
.TP
\f4\-k\f1
\f4csplit\fP
normally removes created files if an error occurs.
If the
\f4\-k\f1
option is present,
\f4csplit\fP
leaves previously created files intact.
.TP
\f4\-f\f2 prefix\f1
If the
\f4\-f\f1
option is used, the created files are named
\f2prefix\f400\c\f1
\&\|.\|.\|.\|\c
.IR prefixn .
The default is
\f4xx00\f1\|.\|.\|.\|\f4xx\f2n\f1.\f1
.RE
.PP
The arguments
.RI ( arg1 "\|.\|.\|.\|" argn )
to
\f4csplit\fP
can be a combination of the following:
.RS 2
.TP 10
.RI / rexp /
A file is to be created for the section from the current line
up to (but not including) the line containing the regular expression
.IR rexp .
The current line becomes the line containing
.IR rexp .
This argument may be followed by an optional
\f4+\f1 or
\f4\-\f1
some number of lines
(e.g., \f4/Page/\-5\fP).
See \f4ed\f1(1) for a description of how
to specify a regular expression.
.TP
.RI % rexp %
This argument is the same as
.RI / rexp /,
except that no file is created for the section.
.TP
.I lnno\^
A file is to be created from the current line up to (but not including)
.IR lnno .
The current line becomes
.IR lnno .
.TP
.RI { num }
Repeat argument.
This argument may follow any of the above arguments.
If it follows a
.I rexp\^
type argument, that argument is applied
.I num\^
more times.
If it follows
.IR lnno ,
the file will be split every
.I lnno\^
lines
.RI ( num\^
times)
from that point.
.RE
.PP
Enclose all
.I rexp\^
type arguments that contain blanks or other characters meaningful to
the shell in the appropriate quotes.
Regular expressions may not contain embedded new-lines.
\f4csplit\fP
does not affect the original file;
it is the user's responsibility to remove it
if it is no longer wanted.
.SH EXAMPLES
.PP
.RS
.ft 4
csplit \-f cobol file '/procedure division/' /par5./ /par16./
.ft 1
.RE
.sp
This example creates four files,
\f4cobol00\f1\|.\|.\|.\|\f4cobol03\f1.
After editing the ``split'' files, they can be recombined as follows:
.PP
.RS
.ft 4
cat cobol0[0\-3] > file
.ft 1
.RE
.PP
Note that this example overwrites the original file.
.PP
.RS
.ft 4
csplit \-k file 100 {99}
.ft 1
.RE
.PP
This example splits the file at every 100 lines, up to 10,000 lines.
The
\f4\-k\f1
option causes the created files to be retained if there
are less than 10,000 lines; however, an error message would
still be printed.
.PP
.RS
.ft 4
csplit \-k prog.c '%main(%\' '/^}/+1' {20}
.ft 1
.RE
.PP
If
\f4prog.c\f1
follows the normal
C
coding convention
(the last line of a routine consists only of a
\f4}\f1
in the first character position),
this example creates a file for each separate
C
routine (up to 21) in
\f4prog.c\f1.
.SH SEE ALSO
\f4ed\fP(1), \f4sh\fP(1).
.SH DIAGNOSTICS
Self-explanatory except for:
.RS
.ft 4
\f2arg\fP \- out of range
.ft 1
.RE
.PP
which means that the given argument did not reference a line
between the current position and the end of the file.
.\"	@(#)csplit.1	6.2 of 9/2/83
.Ee
