1csplit(1)                        User Commands                       csplit(1)
2
3
4

NAME

6       csplit - split  files based on context
7

SYNOPSIS

9       csplit [-ks] [-f prefix] [-n number] file arg1... argn
10
11

DESCRIPTION

13       The csplit utility reads the file named by the file operand, writes all
14       or part of that file into other files as directed by the arg  operands,
15       and writes the sizes of the files.
16

OPTIONS

18       The following options are supported:
19
20       -f prefix    Names  the created files prefix00, prefix01, ..., prefixn.
21                    The default is xx00 ... xxn. If the prefix argument  would
22                    create  a  file name exceeding 14 bytes, an error results.
23                    In that case, csplit exits with a diagnostic  message  and
24                    no files are created.
25
26
27       -k           Leaves previously created files intact. By default, csplit
28                    removes created files if an error occurs.
29
30
31       -n number    Uses number decimal digits to form filenames for the  file
32                    pieces. The default is 2.
33
34
35       -s           Suppresses the output of file size messages.
36
37

OPERANDS

39       The following operands are supported:
40
41       file    The  path  name  of  a text file to be split. If file is -, the
42               standard input will be used.
43
44
45
46       The operands arg1 ... argn can be a combination of the following:
47
48       /rexp/[offset]    Create a file using the content of the lines from the
49                         current  line up to, but not including, the line that
50                         results from the evaluation of the regular expression
51                         with  offset, if any, applied. The regular expression
52                         rexp must follow the rules for basic regular  expres‐
53                         sions.  Regular  expressions  can  include the use of
54                         '\/' and '\%'. These forms must  be  properly  quoted
55                         with  single  quotes,  since  "\"  is  special to the
56                         shell. The optional offset must be a positive or neg‐
57                         ative  integer  value representing a number of lines.
58                         The integer value must be preceded by + or . If  the
59                         selection  of lines from an offset expression of this
60                         type would create a file with zero lines, or one with
61                         greater  than  the  number of lines left in the input
62                         file, the results are unspecified. After the  section
63                         is  created, the current line will be set to the line
64                         that results  from  the  evaluation  of  the  regular
65                         expression with any offset applied. The pattern match
66                         of rexp always is applied from the  current  line  to
67                         the end of the file.
68
69
70       %rexp%[offset]    This  operand  is  the same as /rexp/[offset], except
71                         that no file will be created for the selected section
72                         of the input file.
73
74
75       line_no           Create  a  file  from the current line up to (but not
76                         including) the line number line_no. Lines in the file
77                         will  be  numbered  starting at one. The current line
78                         becomes line_no.
79
80
81       {num}             Repeat operand. This operand can follow  any  of  the
82                         operands  described  previously. If it follows a rexp
83                         type operand, that operand will be applied  num  more
84                         times. If it follows a line_no operand, the file will
85                         be split every line_no lines, num  times,  from  that
86                         point.
87
88
89
90       An  error  will  be  reported  if  an operand does not reference a line
91       between the current position and the end of the file.
92

USAGE

94       See largefile(5) for the description of the  behavior  of  csplit  when
95       encountering files greater than or equal to 2 Gbyte (2^31 bytes).
96

EXAMPLES

98       Example 1 Splitting and combining files
99
100
101       This example creates four files, cobol00...cobol03.
102
103
104         example% csplit -f cobol filename \
105            '/procedure division/' /par5./ /par16./
106
107
108
109
110       After editing the split files, they can be recombined as follows:
111
112
113         example% cat cobol0[0−3] > filename
114
115
116
117
118       This example overwrites the original file.
119
120
121       Example 2 Splitting a file into equal parts
122
123
124       This  example  splits  the file at every 100 lines, up to 10,000 lines.
125       The -k option causes the created files to be retained if there are less
126       than 10,000 lines; however, an error message would still be printed.
127
128
129         example% csplit -k filename 100 {99}
130
131
132
133       Example 3 Creating a file for separate C routines
134
135
136       If  prog.c  follows  the normal C coding convention (the last line of a
137       routine consists only of a } in the  first  character  position),  this
138       example  creates  a  file  for  each  separate  C routine (up to 21) in
139       prog.c.
140
141
142         example% csplit -k prog.c '%main(%' '/^}/+1' {20}
143
144
145

ENVIRONMENT VARIABLES

147       See environ(5) for descriptions of the following environment  variables
148       that   affect  the  execution  of  csplit:  LANG,  LC_ALL,  LC_COLLATE,
149       LC_CTYPE, LC_MESSAGES, and NLSPATH.
150

EXIT STATUS

152       The following exit values are returned:
153
154       0     Successful completion.
155
156
157       >0    An error occurred.
158
159

ATTRIBUTES

161       See attributes(5) for descriptions of the following attributes:
162
163
164
165
166       ┌─────────────────────────────┬─────────────────────────────┐
167       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
168       ├─────────────────────────────┼─────────────────────────────┤
169       │Availability                 │SUNWesu                      │
170       ├─────────────────────────────┼─────────────────────────────┤
171       │CSI                          │Enabled                      │
172       ├─────────────────────────────┼─────────────────────────────┤
173       │Interface Stability          │Standard                     │
174       └─────────────────────────────┴─────────────────────────────┘
175

SEE ALSO

177       sed(1), split(1), attributes(5), environ(5), largefile(5), standards(5)
178

DIAGNOSTICS

180       The diagnostic messages are self-explanatory, except for the following:
181
182       arg − out of range       The given argument did not  reference  a  line
183                                between  the  current  position and the end of
184                                the file.
185
186
187
188
189SunOS 5.11                        4 Dec 2003                         csplit(1)
Impressum