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