CSPLIT(1) | User Commands | CSPLIT(1) |
csplit - split files based on context
csplit [-ks] [-f prefix] [-n number] file arg1... argn
The csplit utility reads the file named by the file operand, writes all or part of that file into other files as directed by the arg operands, and writes the sizes of the files.
The following options are supported:
-f prefix
-k
-n number
-s
The following operands are supported:
file
The operands arg1 ... argn can be a combination of the following:
/rexp/[offset]
%rexp%[offset]
line_no
{num}
An error will be reported if an operand does not reference a line between the current position and the end of the file.
See largefile(7) for the description of the behavior of csplit when encountering files greater than or equal to 2 Gbyte (2^31 bytes).
Example 1 Splitting and combining files
This example creates four files, cobol00...cobol03.
example% csplit -f cobol filename \
'/procedure division/' /par5./ /par16./
After editing the split files, they can be recombined as follows:
example% cat cobol0[0−3] > filename
This example overwrites the original file.
Example 2 Splitting a file into equal parts
This example splits 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.
example% csplit -k filename 100 {99}
Example 3 Creating a file for separate C routines
If prog.c follows the normal C coding convention (the last line of a routine consists only of a } in the first character position), this example creates a file for each separate C routine (up to 21) in prog.c.
example% csplit -k prog.c '%main(%' '/^}/+1' {20}
See environ(7) for descriptions of the following environment variables that affect the execution of csplit: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.
The following exit values are returned:
0
>0
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | Standard |
sed(1), split(1), attributes(7), environ(7), largefile(7), standards(7)
The diagnostic messages are self-explanatory, except for the following:
arg − out of range
December 4, 2003 | OmniOS |