Move everything from /var/adm to /var/log
[unleashed.git] / share / man / man1 / csplit.1
blob09294ae41653b392f51af03324cf21d07716bafa
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
45 .\" Portions Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved
46 .\"
47 .TH CSPLIT 1 "Dec 4, 2003"
48 .SH NAME
49 csplit \- split  files based on context
50 .SH SYNOPSIS
51 .LP
52 .nf
53 \fBcsplit\fR [\fB-ks\fR] [\fB-f\fR \fIprefix\fR] [\fB-n\fR \fInumber\fR] \fIfile\fR \fIarg1\fR... \fIargn\fR
54 .fi
56 .SH DESCRIPTION
57 .sp
58 .LP
59 The \fBcsplit\fR utility reads the file named by the \fIfile\fR operand, writes
60 all or part of that file into other files as directed by the \fIarg\fR
61 operands, and writes the sizes of the files.
62 .SH OPTIONS
63 .sp
64 .LP
65 The following options are supported:
66 .sp
67 .ne 2
68 .na
69 \fB\fB-f\fR\fI prefix\fR\fR
70 .ad
71 .RS 13n
72 Names the created files \fIprefix\fR\fB00\fR, \fIprefix\fR\fB01\fR, ...,
73 \fIprefix\fR\fIn\fR. The default is \fBxx00\fR ... \fBxx\fR\fIn\fR. If the
74 \fIprefix\fR argument would create a file name exceeding \fB14\fR bytes, an
75 error results. In that case, \fBcsplit\fR exits with a diagnostic message and
76 no files are created.
77 .RE
79 .sp
80 .ne 2
81 .na
82 \fB\fB-k\fR\fR
83 .ad
84 .RS 13n
85 Leaves previously created files intact. By default, \fBcsplit\fR removes
86 created files if an error occurs.
87 .RE
89 .sp
90 .ne 2
91 .na
92 \fB\fB-n\fR\fI number\fR\fR
93 .ad
94 .RS 13n
95 Uses \fInumber\fR decimal digits to form filenames for the file pieces. The
96 default is \fB2\fR.
97 .RE
99 .sp
100 .ne 2
102 \fB\fB-s\fR\fR
104 .RS 13n
105 Suppresses the output of file size messages.
108 .SH OPERANDS
111 The following operands are supported:
113 .ne 2
115 \fB\fIfile\fR\fR
117 .RS 8n
118 The path name of a text file to be split. If \fIfile\fR is \fB-\fR, the
119 standard input will be used.
124 The operands \fIarg1\fR ... \fIargn\fR can be a combination of the following:
126 .ne 2
128 \fB/\fIrexp\fR/[\fIoffset\fR]\fR
130 .RS 18n
131 Create a file using the content of the lines from the current line up to, but
132 not including, the line that results from the evaluation of the regular
133 expression with \fIoffset\fR, if any, applied. The regular expression
134 \fIrexp\fR must follow the rules for basic regular expressions. Regular
135 expressions can include the use of '\fB\e/\fR\&' and '\fB\e%\fR\&'. These forms
136 must be properly quoted with single quotes, since "\fB\e\fR" is special to the
137 shell. The optional \fIoffset\fR must be a positive or negative integer value
138 representing a number of lines. The integer value must be preceded by \fB+\fR
139 or \fB\(mi\fR\&. If the selection of lines from an offset expression of this
140 type would create a file with zero lines, or one with greater than the number
141 of lines left in the input file, the results are unspecified. After the section
142 is created, the current line will be set to the line that results from the
143 evaluation of the regular expression with any offset applied. The pattern match
144 of \fIrexp\fR always is applied from the current line to the end of the file.
148 .ne 2
150 \fB%\fIrexp\fR%[\fIoffset\fR]\fR
152 .RS 18n
153 This operand is the same as /\fIrexp\fR/[\fIoffset\fR], except that no file
154 will be created for the selected section of the input file.
158 .ne 2
160 \fB\fIline_no\fR\fR
162 .RS 18n
163 Create a file from the current line up to (but not including) the line number
164 \fIline_no\fR. Lines in the file will be numbered starting at one. The current
165 line becomes \fIline_no\fR.
169 .ne 2
171 \fB{\fInum\fR}\fR
173 .RS 18n
174 Repeat operand. This operand can follow any of the operands described
175 previously. If it follows a \fIrexp\fR type operand, that operand will be
176 applied \fInum\fR more times. If it follows a \fIline_no\fR operand, the file
177 will be split every \fIline_no\fR lines, \fInum\fR times, from that point.
182 An error will be reported if an operand does not reference a line between the
183 current position and the end of the file.
184 .SH EXAMPLES
186 \fBExample 1 \fRSplitting and combining files
189 This example creates four files, \fBcobol00\fR...\fBcobol03\fR.
192 .in +2
194 example% \fBcsplit -f cobol filename \e
195    '/procedure division/' /par5./ /par16./\fR
197 .in -2
202 After editing the \fBsplit\fR files, they can be recombined as follows:
205 .in +2
207 example% \fBcat cobol0[0\(mi3] > \fIfilename\fR\fR
209 .in -2
214 This example overwrites the original file.
217 \fBExample 2 \fRSplitting a file into equal parts
220 This example splits the file at every 100 lines, up to 10,000 lines. The
221 \fB-k\fR option causes the created files to be retained if there are less than
222 10,000 lines; however, an error message would still be printed.
225 .in +2
227 example% \fBcsplit -k filename 100 {99}\fR
229 .in -2
233 \fBExample 3 \fRCreating a file for separate C routines
236 If \fBprog.c\fR follows the normal C coding convention (the last line of a
237 routine consists only of a \fB}\fR in the first character position), this
238 example creates a file for each separate C routine (up to 21) in \fBprog.c\fR.
241 .in +2
243 example% \fBcsplit -k prog.c '%main(%' '/^}/+1' {20}\fR
245 .in -2
248 .SH ENVIRONMENT VARIABLES
251 See \fBenviron\fR(5) for descriptions of the following environment variables
252 that affect the execution of \fBcsplit\fR: \fBLANG\fR, \fBLC_ALL\fR,
253 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
254 .SH EXIT STATUS
257 The following exit values are returned:
259 .ne 2
261 \fB\fB0\fR\fR
263 .RS 6n
264 Successful completion.
268 .ne 2
270 \fB\fB>0\fR\fR
272 .RS 6n
273 An error occurred.
276 .SH ATTRIBUTES
279 See \fBattributes\fR(5) for descriptions of the following attributes:
284 box;
285 c | c
286 l | l .
287 ATTRIBUTE TYPE  ATTRIBUTE VALUE
289 CSI     Enabled
291 Interface Stability     Standard
294 .SH SEE ALSO
297 \fBsed\fR(1), \fBsplit\fR(1), \fBattributes\fR(5), \fBenviron\fR(5),
298 \fBstandards\fR(5)
299 .SH DIAGNOSTICS
302 The diagnostic messages are self-explanatory, except for the following:
304 .ne 2
306 \fB\fIarg\fR \(mi out of range\fR
308 .RS 25n
309 The given argument did not reference a line between the current position and
310 the end of the file.