Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Apropos / Subsearch:
optional field

CSPLIT(1V)                                                          CSPLIT(1V)

       csplit - split a file with respect to a given context

       csplit [ -f prefix ] [ -k ] [ -s ] filename argument1 [ ...argumentn ]

       This  command  is  available  with  the  System V software installation
       option.  Refer to for information on how to install optional software.

       csplit reads the file whose name is filename and separates it into  n+1
       sections, defined by the arguments argument1 through argumentn.  If the
       filename argument is a `-', the standard input is used.  By default the
       sections  are  placed  in  files  named xx00 through xxn.  n may not be
       greater than 99.  These sections receive the following portions of  the

       xx00    From  the  start of filename up to (but not including) the line
               indicated by argument1 (see OPTIONS below for an explanation of
               these arguments.)
       xx01:   From  the  line indicated by argument1 up to the line indicated
               by argument2.
       xxn:    From the line referenced by argumentn to the end of filename.

       csplit prints the character counts for each file created,  and  removes
       any files it creates if an error occurs.

       -f prefix
               name the created files prefix00 through prefixn.

       -k      Suppress removal of created files when an error occurs.

       -s      Suppress printing of character counts.

       The  arguments  argument1 through argumentn can be a combination of the
       following selection operators:

       /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 then becomes the  line  con-
               taining rexp.  This argument may be followed by an optional `+'
               or `-' some number of lines (for example, /Page/-5).

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

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

       {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 lineno, the file will
               be split every lineno 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 new-lines.

       This example splits the file at every 100 lines, up to 10,000 lines.

              csplit -k file  100  {99}

       Assuming  that  prog.c follows the normal C coding convention of ending
       routines with a } at the beginning of the line, this example will  cre-
       ate a file containing each separate C routine (up to 21) in prog.c.

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

       ed(1), sh(1), regexp(3)

       Self-explanatory except for:

              arg - out of range

       which means that the given argument did not refer to a line between the
       current position and the EOF.

                               16 September 1989                    CSPLIT(1V)