csplit
PURPOSE
Splits files by context.
SYNOPSIS
csplit [ -s ] [ -k ] [ -f prefix ] file arg1 [ ... argn ]
DESCRIPTION
The csplit command reads a file and separates it into
segments defined by the specified parameters (parm . . .
). By default, csplit writes these segments to files
xx00+ . . . xxn, where n is the number of parms listed
on the command line (n may not be greater than 99).
These new files get the following pieces of file:
00: From the start of file up to, but not including,
the line referenced by the first parm.
01: From the line referenced by the first parm up to
the line referenced by the second parm.
.
n+1: From the line referenced by the last parm to the
end of file.
Note that csplit does not alter the original file.
The specified parms can be a combination of the fol-
lowing:
/pattern/ Creates a file that contains the segment from
the current line up to (but not including) the
line containing pattern, which becomes the
current line.
%pattern% Makes the line containing pattern the current
line, but does not create a file for the
segment.
+num
-num Moves forward or backward the specified number
of lines from the line matched by an imme-
diately preceding pattern parameter (for
example, "/Page/-5").
linenum Creates a file containing the segment from the
current line up to (but not including)
linenum, which becomes the current line.
{number} Repeats the preceding argument the specified
number of times. This number can follow any
of the pattern or linenum parameters. If it
follows a pattern parameter, csplit reuses
that pattern the specified number of times.
If it follows a linenum parameter, csplit
splits the file from that point every linenum
of lines for the specified number of times.
Quote all pattern parameters that contain blanks or other
characters special to the shell. Patterns may not
contain embedded new-line characters. In an expression
such as [a-z], the minus means "through" according to the
current collating sequence. A collating sequence may
define equivalence classes for use in character ranges.
See the "Overview of International Character Support" in
Managing the AIX Operating System for more information on
collating sequences and equivalence classes.
FLAGS
-f prefix Specifies the prefix name for the created
file segments. xx is the default prefix.
-k Leaves created file segments intact in the
event of an error.
-s Suppresses the display of character counts.
EXAMPLES
1. To split the text of a book into a separate file for
each chapter:
csplit book "/^ Chapter *[0-9]/" {9}
This creates files named xx00, xx01, xx02, . . .
,xx9, which contain individual chapters of the file
"book". Each chapter begins with a line that con-
tains only the word "Chapter" and the chapter number.
The file xx00 contains the front matter that comes
before the first chapter. The "{9}" after the
pattern allows up to 9 chapters.
2. To specify the prefix for the created file names:
csplit -f chap book "/^ Chapter *[0-9]/" {9}
This splits "book" into files named "chap"00,
"chap"01, "chap"02, . . . ,"chap"9.
RELATED INFORMATION
The following commands: "ed," "sh," and "regcmp."
The regxp file in AIX Operating System Technical Refer-
ence.
"Overview of International Character Support" in Managing
the AIX Operating System.