1CSPLIT(1P)                 POSIX Programmer's Manual                CSPLIT(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       csplit — split files based on context
13

SYNOPSIS

15       csplit [-ks] [-f prefix] [-n number] file arg...
16

DESCRIPTION

18       The csplit utility shall read the file named by the file operand, write
19       all  or part of that file into other files as directed by the arg oper‐
20       ands, and write the sizes of the files.
21

OPTIONS

23       The csplit utility shall conform to  the  Base  Definitions  volume  of
24       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
25
26       The following options shall be supported:
27
28       -f prefix Name the created files prefix00, prefix01, ..., prefixn.  The
29                 default is xx00 ...  xxn.  If the prefix argument would  cre‐
30                 ate  a  filename  exceeding  {NAME_MAX} bytes, an error shall
31                 result, csplit shall exit with a diagnostic message,  and  no
32                 files shall be created.
33
34       -k        Leave  previously  created  files  intact. By default, csplit
35                 shall remove created files if an error occurs.
36
37       -n number Use number decimal digits to  form  filenames  for  the  file
38                 pieces. The default shall be 2.
39
40       -s        Suppress the output of file size messages.
41

OPERANDS

43       The following operands shall be supported:
44
45       file      The  pathname of a text file to be split. If file is '-', the
46                 standard input shall be used.
47
48       Each arg operand can be one of the following:
49
50       /rexp/[offset]
51                 A file shall be created using the content of the  lines  from
52                 the  current  line  up  to,  but not including, the line that
53                 results from the evaluation of the  regular  expression  with
54                 offset,  if  any,  applied. The regular expression rexp shall
55                 follow the rules for basic regular expressions  described  in
56                 the  Base  Definitions  volume  of POSIX.1‐2017, Section 9.3,
57                 Basic Regular Expressions.  The  application  shall  use  the
58                 sequence "\/" to specify a <slash> character within the rexp.
59                 The optional offset shall be a positive or  negative  integer
60                 value  representing  a  number  of  lines. A positive integer
61                 value can be preceded by '+'.  If the selection of lines from
62                 an  offset  expression  of this type would create a file with
63                 zero lines, or one with greater than the number of lines left
64                 in  the  input  file,  the results are unspecified. After the
65                 section is created, the current line shall be set to the line
66                 that  results  from  the evaluation of the regular expression
67                 with any offset applied. If the current  line  is  the  first
68                 line  in  the file and a regular expression operation has not
69                 yet been performed,  the  pattern  match  of  rexp  shall  be
70                 applied from the current line to the end of the file.  Other‐
71                 wise, the pattern match of rexp shall  be  applied  from  the
72                 line following the current line to the end of the file.
73
74       %rexp%[offset]
75                 Equivalent  to  /rexp/[offset],  except that no file shall be
76                 created for the selected  section  of  the  input  file.  The
77                 application  shall  use  the sequence "\%" to specify a <per‐
78                 cent-sign> character within the rexp.
79
80       line_no   Create a file from the current line up to (but not including)
81                 the line number line_no.  Lines in the file shall be numbered
82                 starting at one. The current line becomes line_no.
83
84       {num}     Repeat operand. This operand can follow any of  the  operands
85                 described previously. If it follows a rexp type operand, that
86                 operand shall be applied num more  times.  If  it  follows  a
87                 line_no operand, the file shall be split every line_no lines,
88                 num times, from that point.
89
90       An error shall be reported if an operand  does  not  reference  a  line
91       between the current position and the end of the file.
92

STDIN

94       See the INPUT FILES section.
95

INPUT FILES

97       The input file shall be a text file.
98

ENVIRONMENT VARIABLES

100       The  following  environment  variables  shall  affect  the execution of
101       csplit:
102
103       LANG      Provide a default value for  the  internationalization  vari‐
104                 ables  that are unset or null. (See the Base Definitions vol‐
105                 ume of POSIX.1‐2017, Section 8.2, Internationalization  Vari‐
106                 ables  for  the  precedence of internationalization variables
107                 used to determine the values of locale categories.)
108
109       LC_ALL    If set to a non-empty string value, override  the  values  of
110                 all the other internationalization variables.
111
112       LC_COLLATE
113                 Determine  the locale for the behavior of ranges, equivalence
114                 classes, and multi-character collating elements within  regu‐
115                 lar expressions.
116
117       LC_CTYPE  Determine  the  locale for the interpretation of sequences of
118                 bytes of text data as characters (for example, single-byte as
119                 opposed  to  multi-byte  characters  in  arguments  and input
120                 files) and the behavior of character classes  within  regular
121                 expressions.
122
123       LC_MESSAGES
124                 Determine the locale that should be used to affect the format
125                 and contents  of  diagnostic  messages  written  to  standard
126                 error.
127
128       NLSPATH   Determine the location of message catalogs for the processing
129                 of LC_MESSAGES.
130

ASYNCHRONOUS EVENTS

132       If the -k option is specified, created files shall be retained.  Other‐
133       wise, the default action occurs.
134

STDOUT

136       Unless  the -s option is used, the standard output shall consist of one
137       line per file created, with a format as follows:
138
139
140           "%d\n", <file size in bytes>
141

STDERR

143       The standard error shall be used only for diagnostic messages.
144

OUTPUT FILES

146       The output files shall contain portions of  the  original  input  file;
147       otherwise, unchanged.
148

EXTENDED DESCRIPTION

150       None.
151

EXIT STATUS

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

CONSEQUENCES OF ERRORS

160       By default, created files shall be removed if an error occurs. When the
161       -k option is specified, created files shall not be removed if an  error
162       occurs.
163
164       The following sections are informative.
165

APPLICATION USAGE

167       None.
168

EXAMPLES

170        1. This example creates four files, cobol00 ...  cobol03:
171
172
173               csplit -f cobol file '/procedure division/' /par5./ /par16./
174
175           After editing the split files, they can be recombined as follows:
176
177
178               cat cobol0[0-3] > file
179
180           Note that this example overwrites the original file.
181
182        2. This  example  would  split  the file after the first 99 lines, and
183           every 100 lines thereafter, up to 9999 lines; this is because lines
184           in  the  file  are numbered from 1 rather than zero, for historical
185           reasons:
186
187
188               csplit -k file  100  {99}
189
190        3. Assuming that prog.c follows the C-language  coding  convention  of
191           ending routines with a '}' at the beginning of the line, this exam‐
192           ple creates a file containing each separate C routine (up to 21) in
193           prog.c:
194
195
196               csplit -k prog.c '%main(%'  '/^}/+1' {20}
197

RATIONALE

199       The  -n option was added to extend the range of filenames that could be
200       handled.
201
202       Consideration was given to adding a -a flag to use the alphabetic file‐
203       name generation used by the historical split utility, but the function‐
204       ality added by the -n option  was  deemed  to  make  alphabetic  naming
205       unnecessary.
206

FUTURE DIRECTIONS

208       None.
209

SEE ALSO

211       sed, split
212
213       The  Base  Definitions  volume  of POSIX.1‐2017, Chapter 8, Environment
214       Variables, Section 9.3, Basic Regular Expressions, Section 12.2,  Util‐
215       ity Syntax Guidelines
216
218       Portions  of  this text are reprinted and reproduced in electronic form
219       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
220       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
221       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
222       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
223       event of any discrepancy between this version and the original IEEE and
224       The  Open Group Standard, the original IEEE and The Open Group Standard
225       is the referee document. The original Standard can be  obtained  online
226       at http://www.opengroup.org/unix/online.html .
227
228       Any  typographical  or  formatting  errors that appear in this page are
229       most likely to have been introduced during the conversion of the source
230       files  to  man page format. To report such errors, see https://www.ker
231       nel.org/doc/man-pages/reporting_bugs.html .
232
233
234
235IEEE/The Open Group                  2017                           CSPLIT(1P)
Impressum