Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

sh(1)

regexp(3)

CSPLIT(1)  —  USER COMMANDS

NAME

csplit − context split

SYNOPSIS

csplit [ −f prefix ] [ −k ] [ −s ] filename arg1 [ ... argn ]

DESCRIPTION

csplit reads the file whose name is filename and separates it into n+1 sections, defined by the arguments arg1 through argn. If the filename argument is a −, the standard input is used.  By default the sections are placed in files named xx00 through xxn.  n may not be greater than 99.  These sections receive the following portions of the file:

xx00 From the start of filename up to (but not including) the line indicated by arg1 (see OPTIONS below for an explanation of these arguments.) 

xx01: From the line indicated by arg1 up to the line indicated by arg2.

. 
.
.

xxn: From the line referenced by argn to the end of file.

csplit prints the character counts for each file created, and removes any files it creates if an error occurs. 

OPTIONS

−f prefix
name the created files prefix00 through prefixn.

−k suppress removal of created files when an error occurs. 

−s suppress printing of character counts. 

The arguments arg1 through argn can be a combination of the following selection operators:

/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 then becomes the line containing rexp. This argument may be followed by an optional + or − some number of lines (e.g., /Page/−5). 

%rexp%
This argument is the same as /rexp/, except that no file is created for the selected section.

lineno A file is to be created from the current line up to (but not including) lineno. The current line becomes lineno.

{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 lineno, the file will be split every lineno 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 new-lines. 

EXAMPLES

This example splits the file at every 100 lines, up to 10,000 lines. 

csplit −k file  100  {99}

Assuming that prog.c follows the normal C coding convention of ending routines with a } at the beginning of the line, this example will create a file containing each separate C routine (up to 21) in prog.c. 

csplit −k prog.c  ′%main(%′  ′/^}/+1′  {20}

SEE ALSO

ed(1), sh(1), regexp(3)

DIAGNOSTICS

Self-explanatory except for:

arg − out of range

which means that the given argument did not refer to a line between the current position and the end of the file. 

Sun Release 3.2  —  Last change: 28 March 1986

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026