{
    "mode": "info",
    "parameter": "csplit",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/csplit/json",
    "generated": "2026-11-14T12:13:03Z",
    "sections": {
        "File: coreutils.info,  Node: csplit invocation,  Prev: split invocation,  Up: Output of parts of files": {
            "content": "",
            "subsections": [
                {
                    "name": "5.4 'csplit': Split a file into context-determined pieces",
                    "content": "'csplit' creates zero or more output files containing sections of INPUT\n(standard input if INPUT is '-').  Synopsis:\n\ncsplit [OPTION]... INPUT PATTERN...\n\nThe contents of the output files are determined by the PATTERN\narguments, as detailed below.  An error occurs if a PATTERN argument\nrefers to a nonexistent line of the input file (e.g., if no remaining\nline matches a given regular expression).  After every PATTERN has been\nmatched, any remaining input is copied into one last output file.\n\nBy default, 'csplit' prints the number of bytes written to each\noutput file after it has been created.\n\nThe types of pattern arguments are:\n\n'N'\nCreate an output file containing the input up to but not including\nline N (a positive integer).  If followed by a repeat count, also\ncreate an output file containing the next N lines of the input file\nonce for each repeat.\n\n'/REGEXP/[OFFSET]'\nCreate an output file containing the current line up to (but not\nincluding) the next line of the input file that contains a match\nfor REGEXP.  The optional OFFSET is an integer, that can be\npreceded by '+' or '-'.  If it is given, the input up to (but not\nincluding) the matching line plus or minus OFFSET is put into the\noutput file, and the line after that begins the next section of\ninput.  Note lines within a negative offset of a regexp pattern are\nnot matched in subsequent regexp patterns.\n\n'%REGEXP%[OFFSET]'\nLike the previous type, except that it does not create an output\nfile, so that section of the input file is effectively ignored.\n\n'{REPEAT-COUNT}'\nRepeat the previous pattern REPEAT-COUNT additional times.  The\nREPEAT-COUNT can either be a positive integer or an asterisk,\nmeaning repeat as many times as necessary until the input is\nexhausted.\n\nThe output files' names consist of a prefix ('xx' by default)\nfollowed by a suffix.  By default, the suffix is an ascending sequence\nof two-digit decimal numbers from '00' to '99'.  In any case,\nconcatenating the output files in sorted order by file name produces the\noriginal input file, excluding portions skipped with a %REGEXP% pattern\nor the '--suppress-matched' option.\n\nBy default, if 'csplit' encounters an error or receives a hangup,\ninterrupt, quit, or terminate signal, it removes any output files that\nit has created so far before it exits.\n\nThe program accepts the following options.  Also see *note Common\noptions::.\n\n'-f PREFIX'\n'--prefix=PREFIX'\nUse PREFIX as the output file name prefix.\n\n'-b FORMAT'\n'--suffix-format=FORMAT'\nUse FORMAT as the output file name suffix.  When this option is\nspecified, the suffix string must include exactly one\n'printf(3)'-style conversion specification, possibly including\nformat specification flags, a field width, a precision\nspecification, or all of these kinds of modifiers.  The format\nletter must convert a binary unsigned integer argument to readable\nform.  The format letters 'd' and 'i' are aliases for 'u', and the\n'u', 'o', 'x', and 'X' conversions are allowed.  The entire FORMAT\nis given (with the current output file number) to 'sprintf(3)' to\nform the file name suffixes for each of the individual output files\nin turn.  If this option is used, the '--digits' option is ignored.\n\n'-n DIGITS'\n'--digits=DIGITS'\nUse output file names containing numbers that are DIGITS digits\nlong instead of the default 2.\n\n'-k'\n'--keep-files'\nDo not remove output files when errors are encountered.\n\n'--suppress-matched'\nDo not output lines matching the specified PATTERN.  I.e., suppress\nthe boundary line from the start of the second and subsequent\nsplits.\n\n'-z'\n'--elide-empty-files'\nSuppress the generation of zero-length output files.  (In cases\nwhere the section delimiters of the input file are supposed to mark\nthe first lines of each of the sections, the first output file will\ngenerally be a zero-length file unless you use this option.)  The\noutput file sequence numbers always run consecutively starting from\n0, even when this option is specified.\n\n'-s'\n'-q'\n'--silent'\n'--quiet'\nDo not print counts of output file sizes.\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n\nHere is an example of its usage.  First, create an empty directory\nfor the exercise, and cd into it:\n\n$ mkdir d && cd d\n\nNow, split the sequence of 1..14 on lines that end with 0 or 5:\n\n$ seq 14 | csplit - '/[05]$/' '{*}'\n8\n10\n15\n\nEach number printed above is the size of an output file that csplit\nhas just created.  List the names of those output files:\n\n$ ls\nxx00  xx01  xx02\n\nUse 'head' to show their contents:\n\n$ head xx*\n==> xx00 <==\n1\n2\n3\n4\n\n==> xx01 <==\n5\n6\n7\n8\n9\n\n==> xx02 <==\n10\n11\n12\n13\n14\n\nExample of splitting input by empty lines:\n\n$ csplit --suppress-matched INPUT.TXT '/^$/' '{*}'\n"
                }
            ]
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}