Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ csplit(1) — CLIX 3.1r7.6.22

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

sh(1)

regexp(0)



  csplit(1)                           CLIX                           csplit(1)



  NAME

    csplit - Splits a file based on context

  SYNOPSIS

    csplit [-s] [-k] [-f prefix] file arg1 [ ... argn]

  FLAGS

    -s          Suppresses the displaying of all character counts.  The csplit
                command normally displays the character counts for each file
                created.

    -k          Leaves previously created files intact.  The csplit command
                normally removes created files if an error occurs.

    -f prefix   Names created files prefix00 ... prefixn.  The default is xx00
                ... xxn..

  DESCRIPTION

    The csplit command reads file and separates it into n+1 sections, defined
    by the arguments arg1 ... argn.  By default the sections are placed in
    xx00 ... xx n (n may not be greater than 99).  These sections get the
    following pieces of file.

    00:    From the start of file up to (but not including) the line
           referenced by arg1.

    01:    From the line referenced by arg1 up to the line referenced by arg2.

           .

           .

           .

    N+1:   From the line referenced by argn to the end of file.

    If the file argument is a - then stdin is used.

    The arguments (arg1 ... argn) to csplit can be a combination of the
    following:

    /rexp/     A file is to be created for the section from the current line
               up to (but not including) the line containing the regular
               expression rexp.  The current line becomes the line containing
               rexp.  This argument may be followed by an flagal + or - some
               number of lines (for example, /Page/-5).




  2/94 - Intergraph Corporation                                              1






  csplit(1)                           CLIX                           csplit(1)



    % rexp %   This argument is the same as /rexp/ except that no file is
               created for the section.

    lnno       A file is to be created from the current line up to (but not
               including) lnno.  The current line becomes lnno.

    {num}      Repeat argument.  This argument may follow any of the above
               arguments.  If it follows a rexp type argument, that argument
               is applied num more times.  If it follows lnno, the file will
               be split every lnno lines (num times) from that point.

    Enclose all rexp type arguments that contain blanks or other characters
    meaningful to the shell in the appropriate quotes.  Regular expressions
    may not contain embedded newlines.  The csplit utility does not affect the
    original file; it is the users responsibility to remove it.

  EXAMPLES

    1.  To create four files, cobol00 ... cobol03 and recombine them after
        editing the ``split'' files:

        csplit -f cobol file '/procedure division/' /par5./ /par16./
        cat cobol0[0-3] > file

        Note that this example overwrites the original file.

    2.  To split the file at every 100 lines, up to 10,000 lines:

        csplit -k file 100 {99}

        The -k flag causes the created files to be retained if there are less
        than 10,000 lines; however, an error message would still be displayed.

    3.  To create a file containing each separate C routine (up to 21) in
        prog.c:

        csplit -k prog.c '%main(%' ' /^}/+1' {20}

        This example assumes that prog.c follows the normal C coding
        convention of ending routines with a } at the beginning of the line.

  DIAGNOSTICS

    Self-explanatory except for:

    arg - out of range

    The given argument did not reference a line between the current position
    and the end of the file.

  EXIT VALUES



  2                                              Intergraph Corporation - 2/94






  csplit(1)                           CLIX                           csplit(1)



    The csplit command exits with a value of 1 if a problem is encountered.

  RELATED INFORMATION

    Commands: ed(1),sh(1)

    Miscellany: regexp(0)















































  2/94 - Intergraph Corporation                                              3




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026