CSPLIT(1) COMMAND REFERENCE CSPLIT(1)
NAME
csplit - context split
SYNOPSIS
csplit [-c] [-s] [-k] [-f prefix ] filename arg1... [ argn ]
DESCRIPTION
Csplit reads filename and separates it into n+1 sections,
defined by the arguments arg1... argn. By default the
sections are placed in xx00 ... xx n (n may not be greater
than 99). These sections get the following pieces of
filename:
00: From the start of filename up to (but not
including) the line referenced by arg1.
01: From the line referenced by arg1 up to the line
referenced by arg2.
.
.
.
n+1: From the line referenced by argn to the end of
filename.
OPTIONS
-c Print the number of files created instead of the sizes
of the files. If the -s option is also given, the -c
option is turned off.
-f prefix
If the -f option is used, the created files are named
prefix00 ... prefixn. The default is xx00 ... xxn.
-k Csplit normally removes created files if an error
occurs. If the -k option is present, csplit leaves
previously created files intact.
-s Csplit normally prints the character counts for each
file created. If the -s option is present, csplit
suppresses the printing of all character counts.
The arguments (arg1 ... argn) to csplit can be a
combination of the following:
/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 rexp.
The current line becomes the line containing
rexp. This argument may be followed by an
optional + or - some number of lines (for
example, /Page/-5).
%rexp% This argument is the same as /rexp/, except
Printed 10/17/86 1
CSPLIT(1) COMMAND REFERENCE CSPLIT(1)
that no file is created for the section.
lnno A file is to be created from the current line
up to, but not including, lnno (line number).
The current line becomes lnno.
{num} Repeat argument. This argument may follow any
of the above arguments. If it follows a rexp
type argument, that argument is applied num
more times. If it follows lnno, the file will
be split every lnno lines (num times) from
that point.
Enclose all rexp type arguments that contain blanks or other
characters meaningful to the Shell in the appropriate
quotes. Regular expressions may not contain embedded
newlines. Csplit does not affect the original file; it is
the user's responsibility to remove it.
EXAMPLES
This example creates four files, cobol100...cobol103:
csplit -f cobol file '/procedure division/' /par5./ /par16./
After editing the split files, they can be recombined as
follows:
cat cobol0[0-3] > file
Note that this example overwrites the original file.
This next example would split the file at every 100 lines,
up to 10,000 lines. The -k option causes the created files
to be retained if there are less than 10,000 lines; however,
an error message would still be printed:
csplit -k file 100 {99}
Assuming that prog.c follows the normal C coding convention
of ending routines with a } (close brace) at the beginning
of the line, this example will create a file containing each
Printed 10/17/86 2
CSPLIT(1) COMMAND REFERENCE CSPLIT(1)
separate C routine (up to 21) in prog.c:
csplit -k prog.c '%main(%' '/^}/+1' {20}
RETURN VALUE
[NO_ERRS] Command completed without error.
[USAGE] Incorrect command line syntax. Execution
terminated.
[NP_ERR] An error occurred that was not a system
error. Execution terminated.
[P_ERR] A system error occurred. Execution
terminated. See intro(2) for more
information on system errors.
SEE ALSO
ed(1), sh(1sh).
Printed 10/17/86 3
%%index%%
na:72,58;
sy:130,252;
de:382,927;
op:1309,1803;3256,1000;
ex:4256,938;5338,121;
rv:5459,511;
se:5970,118;
%%index%%000000000139