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 April 28, 2002 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 39.Bk 40.Op Ar args ... 41.Ek 42.Sh DESCRIPTION 43The 44.Nm 45utility splits 46.Ar file 47into pieces using the patterns 48.Ar args... . 49If 50.Ar file 51is 52a dash 53.Pq Ql \&- , 54.Nm 55reads from standard input. 56.Pp 57The options are as follows: 58.Bl -tag -width indent 59.It Fl f Ar prefix 60Give created files names beginning with 61.Ar prefix . 62The default is 63.Sq Pa xx . 64.It Fl k 65Do not remove output files if an error occurs or a 66.Dv HUP , 67.Dv INT 68or 69.Dv TERM 70signal is received. 71.It Fl n Ar number 72Use 73.Ar number 74of decimal digits after the 75.Ar prefix 76to form the file name. The default is 2. 77.It Fl s 78Do not write the size of each output file to standard output as it is 79created. 80.El 81.Pp 82The 83.Ar args... 84operands may be a combination of the following patterns: 85.Bl -tag -width "line_no" 86.It Cm / Ns Ar regexp Ns Cm / Ns Oo Oo +|- Oc Ns Ar offset Oc 87Create a file containing the input from the current line to (but not including) 88the next line matching the given basic regular expression. 89An optional 90.Ar offset 91from the line that matched may be specified. 92.It Cm % Ns Ar regexp Ns Cm % Ns Oo Oo +|- Oc Ns Ar offset Oc 93Same as above but a file is not created for the output. 94.It Ar line_no 95Create containing the input from the current line to (but not including) 96the specified line number. 97.It Cm { Ns Ar num Ns Cm } 98Repeat the previous pattern the specified number of times. 99If it follows a line number pattern, a new file will be created for each 100.Em line_no 101lines, 102.Em num 103times. 104The first line of the file is line number 1 for historic reasons. 105.El 106.Pp 107After all the patterns have been processed, the remaining input data 108(if there is any) will be written to a new file. 109.Pp 110Requesting to split at a line before the current line number or past the 111end of the file will result in an error. 112.Sh EXAMPLES 113Split the 114.Xr mdoc 7 115file 116.Pa foo.1 117into one file for each section (up to 20): 118.Pp 119.D1 Ic csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}' 120.Pp 121Split standard input after the first 99 lines and every 100 lines thereafter: 122.Pp 123.D1 Ic csplit -k - 100 '{19}' 124.Sh DIAGNOSTICS 125.Ex -std 126.Sh SEE ALSO 127.Xr sed 1 , 128.Xr split 1 , 129.Xr re_format 7 130.Sh STANDARDS 131The 132.Nm 133utility conforms to 134.St -p1003.1-2001 . 135