1.\" Copyright (c) 2002 Tim J. Robbins. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.Dd January 26, 2005 28.Dt CSPLIT 1 29.Os 30.Sh NAME 31.Nm csplit 32.Nd split files based on context 33.Sh SYNOPSIS 34.Nm 35.Op Fl ks 36.Op Fl f Ar prefix 37.Op Fl n Ar number 38.Ar file args ... 39.Sh DESCRIPTION 40The 41.Nm 42utility splits 43.Ar file 44into pieces using the patterns 45.Ar args . 46If 47.Ar file 48is 49a dash 50.Pq Sq Fl , 51.Nm 52reads from standard input. 53.Pp 54The options are as follows: 55.Bl -tag -width indent 56.It Fl f Ar prefix 57Give created files names beginning with 58.Ar prefix . 59The default is 60.Dq Pa xx . 61.It Fl k 62Do not remove output files if an error occurs or a 63.Dv HUP , 64.Dv INT 65or 66.Dv TERM 67signal is received. 68.It Fl n Ar number 69Use 70.Ar number 71of decimal digits after the 72.Ar prefix 73to form the file name. 74The default is 2. 75.It Fl s 76Do not write the size of each output file to standard output as it is 77created. 78.El 79.Pp 80The 81.Ar args 82operands may be a combination of the following patterns: 83.Bl -tag -width indent 84.It Xo 85.Sm off 86.Cm / Ar regexp Cm / Op Oo Cm + | - Oc Ar offset 87.Sm on 88.Xc 89Create a file containing the input from the current line to (but not including) 90the next line matching the given basic regular expression. 91An optional 92.Ar offset 93from the line that matched may be specified. 94.It Xo 95.Sm off 96.Cm % Ar regexp Cm % Op Oo Cm + | - Oc Ar offset 97.Sm on 98.Xc 99Same as above but a file is not created for the output. 100.It Ar line_no 101Create containing the input from the current line to (but not including) 102the specified line number. 103.It Cm { Ns Ar num Ns Cm } 104Repeat the previous pattern the specified number of times. 105If it follows a line number pattern, a new file will be created for each 106.Ar line_no 107lines, 108.Ar num 109times. 110The first line of the file is line number 1 for historic reasons. 111.El 112.Pp 113After all the patterns have been processed, the remaining input data 114(if there is any) will be written to a new file. 115.Pp 116Requesting to split at a line before the current line number or past the 117end of the file will result in an error. 118.Sh ENVIRONMENT 119The 120.Ev LANG , LC_ALL , LC_COLLATE 121and 122.Ev LC_CTYPE 123environment variables affect the execution of 124.Nm 125as described in 126.Xr environ 7 . 127.Sh EXIT STATUS 128.Ex -std 129.Sh EXAMPLES 130Split the 131.Xr mdoc 7 132file 133.Pa foo.1 134into one file for each section (up to 20): 135.Pp 136.Dl "csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'" 137.Pp 138Split standard input after the first 99 lines and every 100 lines thereafter: 139.Pp 140.Dl "csplit -k - 100 '{19}'" 141.Sh SEE ALSO 142.Xr sed 1 , 143.Xr split 1 , 144.Xr re_format 7 145.Sh STANDARDS 146The 147.Nm 148utility conforms to 149.St -p1003.1-2001 . 150.Sh HISTORY 151A 152.Nm 153command appeared in PWB UNIX. 154.Sh BUGS 155Input lines are limited to 156.Dv LINE_MAX 157(2048) bytes in length. 158