csplitsplit a text file according to criteria |
Command |
csplit
[-Aaks]
[-f prefix]
[-n number]
file arg arg ...
csplit takes a text file as input and breaks up its
contents into pieces, based on criteria given by the arg value(s) on the
command line. For example, you can use csplit to break up a
text file into chunks of ten lines each, then save each of those chunks in a
separate file. See the subsection
Splitting Criteria for more details.
If you specify - as the file argument,
csplit uses the standard input.
The files created by csplit normally have names of the form
where number is a two digit decimal number which begins at zero and increments by one for each new file thatxxnumber
csplit creates.
csplit also displays the size, in bytes, of each file that
it creates.
-Auses uppercase letters in place of numbers in the number portion of
created file names. This generates names of the form xxAA,
xxAB, and so on.
-auses lowercase letters in place of numbers in the number portion of
created file names. This generates names of the form xxaa,
xxab, and so on.
-f prefixspecifies a prefix to use in place of the default
xx when naming files. If prefix causes a file name
longer than NAME_MAX bytes an error occurs and
csplit exits without creating any files.
-kleaves all created files intact. Normally, when an error occurs,
csplit removes files that it has created.
-n numberspecifies the number of digits in the number portion of created file names.
-ssuppresses the display of file sizes.
csplit processes the args on the command line
sequentially. The first argument breaks off the first chunk of the file,
the second argument breaks off the next chunk (beginning at the first
line remaining in the file) and so on. Thus each chunk of the file begins with
the first line remaining in the file and goes to the line given by the next
arg.
arg values may take any of the following forms:
takes the chunk as all the lines from the current line up to
but not including the next line that contains a string
matching the regular expression regexp. regexp is a basic
regular expression (see
regexp). After
csplit has obtained the chunk and written it to an
output file, it sets the current line to the line that matched
regexp.
is the same as the previous criterion, except that the chunk goes up to
but not including the line that is a given offset from the first
line containing a string that matches regexp. The offset may
be a positive or negative integer. After csplit has
obtained the chunk and written it to an output file, it sets the current
line to the line that matched regexp.
is the same as /regexp/ except that csplit
does not write the chunk to an output file. It simply skips over the
chunk.
is the same as /regexp/offset except
csplit does not write the chunk to an output file.
obtains a chunk beginning at the current line and going up to but not
including the linenumberth line. After csplit
writes the chunk to an output file, it sets the current line to
linenumber.
repeats the previous criterion number times. If it follows a
regular expression criterion, it repeats the regular expression process
number more times. If it follows a linenumber criterion,
csplit splits the file every linenumber lines,
number times, beginning at the current line. For example,
csplit file 10 {10}
obtains a chunk from line 1 to line 9, then every 10 lines after that, up to line 109.
0Successful completion.
1Failure due to any of the following:
csplit was unable to open the
input or output files2Failure due to any of the following:
-f-n{number} repetition count was misplaced or
badly formed-n-A and -a options are extensions to
the POSIX and XPG standards.
regexp