xref: /openbsd-src/usr.bin/csplit/csplit.1 (revision 881f6c5ff077fe814539e359736601c57260e2c7)
1*881f6c5fSkn.\"	$OpenBSD: csplit.1,v 1.13 2022/12/22 19:53:22 kn Exp $
278784257Smillert.\"
378784257Smillert.\" Copyright (c) 2002 Tim J. Robbins.
478784257Smillert.\" All rights reserved.
578784257Smillert.\"
678784257Smillert.\" Redistribution and use in source and binary forms, with or without
778784257Smillert.\" modification, are permitted provided that the following conditions
878784257Smillert.\" are met:
978784257Smillert.\" 1. Redistributions of source code must retain the above copyright
1078784257Smillert.\"    notice, this list of conditions and the following disclaimer.
1178784257Smillert.\" 2. Redistributions in binary form must reproduce the above copyright
1278784257Smillert.\"    notice, this list of conditions and the following disclaimer in the
1378784257Smillert.\"    documentation and/or other materials provided with the distribution.
1478784257Smillert.\"
1578784257Smillert.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1678784257Smillert.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1778784257Smillert.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1878784257Smillert.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1978784257Smillert.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2078784257Smillert.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2178784257Smillert.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2278784257Smillert.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2378784257Smillert.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2478784257Smillert.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2578784257Smillert.\" SUCH DAMAGE.
2678784257Smillert.\"
2778784257Smillert.\" $FreeBSD: src/usr.bin/csplit/csplit.1,v 1.11 2005/01/25 22:29:51 tjr Exp $
2878784257Smillert.\"
29*881f6c5fSkn.Dd $Mdocdate: December 22 2022 $
3078784257Smillert.Dt CSPLIT 1
3178784257Smillert.Os
3278784257Smillert.Sh NAME
3378784257Smillert.Nm csplit
3478784257Smillert.Nd split files based on context
3578784257Smillert.Sh SYNOPSIS
3678784257Smillert.Nm
3778784257Smillert.Op Fl ks
3878784257Smillert.Op Fl f Ar prefix
3978784257Smillert.Op Fl n Ar number
40*881f6c5fSkn.Ar file
41*881f6c5fSkn.Ar arg ...
4278784257Smillert.Sh DESCRIPTION
4378784257SmillertThe
4478784257Smillert.Nm
4578784257Smillertutility splits
4678784257Smillert.Ar file
47*881f6c5fSkninto pieces using the pattern
48*881f6c5fSkn.Ar arg .
4978784257SmillertIf
5078784257Smillert.Ar file
5178784257Smillertis
5278784257Smillerta dash
5378784257Smillert.Pq Sq - ,
5478784257Smillert.Nm
5578784257Smillertreads from standard input.
5678784257Smillert.Pp
57d9b44e58SjmcFiles are created with a prefix of
58d9b44e58Sjmc.Dq xx
59d9b44e58Sjmcand two decimal digits.
60d9b44e58SjmcThe size of each file is written to standard output
61d9b44e58Sjmcas it is created.
62d9b44e58SjmcIf an error occurs whilst files are being created,
63d9b44e58Sjmcor a
64d9b44e58Sjmc.Dv HUP ,
65d9b44e58Sjmc.Dv INT ,
66d9b44e58Sjmcor
67d9b44e58Sjmc.Dv TERM
68d9b44e58Sjmcsignal is received,
69d9b44e58Sjmcall files previously written are removed.
70d9b44e58Sjmc.Pp
7178784257SmillertThe options are as follows:
7278784257Smillert.Bl -tag -width indent
7378784257Smillert.It Fl f Ar prefix
74d9b44e58SjmcCreate file names beginning with
75d9b44e58Sjmc.Ar prefix ,
76d9b44e58Sjmcinstead of
7778784257Smillert.Dq xx .
7878784257Smillert.It Fl k
79d9b44e58SjmcDo not remove previously created files if an error occurs or a
8078784257Smillert.Dv HUP ,
8178784257Smillert.Dv INT ,
8278784257Smillertor
8378784257Smillert.Dv TERM
8478784257Smillertsignal is received.
8578784257Smillert.It Fl n Ar number
86d9b44e58SjmcCreate file names beginning with
8778784257Smillert.Ar number
88d9b44e58Sjmcof decimal digits after the prefix,
89d9b44e58Sjmcinstead of 2.
9078784257Smillert.It Fl s
9178784257SmillertDo not write the size of each output file to standard output as it is
9278784257Smillertcreated.
9378784257Smillert.El
9478784257Smillert.Pp
9578784257SmillertThe
96*881f6c5fSkn.Ar arg
97*881f6c5fSknoperand may be a combination of the following patterns:
9878784257Smillert.Bl -tag -width indent
9978784257Smillert.It Xo
10078784257Smillert.Sm off
10178784257Smillert.No / Ar regexp No /
10278784257Smillert.Op Oo Cm + | - Oc Ar offset
10378784257Smillert.Sm on
10478784257Smillert.Xc
10578784257SmillertCreate a file containing the input from the current line to (but not including)
10678784257Smillertthe next line matching the given basic regular expression.
10778784257SmillertAn optional
10878784257Smillert.Ar offset
10978784257Smillertfrom the line that matched may be specified.
11078784257Smillert.It Xo
11178784257Smillert.Sm off
11278784257Smillert.No % Ar regexp No %
11378784257Smillert.Op Oo Cm + | - Oc Ar offset
11478784257Smillert.Sm on
11578784257Smillert.Xc
11678784257SmillertSame as above but a file is not created for the output.
11778784257Smillert.It Ar line_no
11878784257SmillertCreate containing the input from the current line to (but not including)
11978784257Smillertthe specified line number.
12078784257Smillert.It { Ns Ar num Ns }
12178784257SmillertRepeat the previous pattern the specified number of times.
12278784257SmillertIf it follows a line number pattern, a new file will be created for each
12378784257Smillert.Ar line_no
12478784257Smillertlines,
12578784257Smillert.Ar num
12678784257Smillerttimes.
12778784257SmillertThe first line of the file is line number 1 for historic reasons.
12878784257Smillert.El
12978784257Smillert.Pp
13078784257SmillertAfter all the patterns have been processed, the remaining input data
13178784257Smillert(if there is any) will be written to a new file.
13278784257Smillert.Pp
13378784257SmillertRequesting to split at a line before the current line number or past the
13478784257Smillertend of the file will result in an error.
135f1c64ac4Sjmc.Sh EXIT STATUS
13620197bc1Sjmc.Ex -std csplit
13778784257Smillert.Sh EXAMPLES
13878784257SmillertSplit the
13978784257Smillert.Xr mdoc 7
14078784257Smillertfile
14178784257Smillert.Pa foo.1
1429d92b858Szhukinto one file for each section (up to 21 files):
14378784257Smillert.Pp
14403e2546cSjmc.Dl "$ csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'"
14578784257Smillert.Pp
1469d92b858SzhukSplit standard input after the first 99 lines and every 100 lines
1479d92b858Szhukthereafter (up to 21 files):
14878784257Smillert.Pp
14903e2546cSjmc.Dl "$ csplit -k - 100 '{19}'"
15078784257Smillert.Sh SEE ALSO
15178784257Smillert.Xr sed 1 ,
15278784257Smillert.Xr split 1 ,
15378784257Smillert.Xr re_format 7
15478784257Smillert.Sh STANDARDS
15578784257SmillertThe
15678784257Smillert.Nm
1577c5a075bSjmcutility is compliant with the
15899332e38Sjmc.St -p1003.1-2008
1597c5a075bSjmcspecification.
16078784257Smillert.Sh HISTORY
16178784257SmillertA
16278784257Smillert.Nm
163d9f1e411Ssobradocommand appeared in PWB
164d9f1e411Ssobrado.Ux .
16578784257Smillert.Sh BUGS
16678784257SmillertInput lines are limited to
16778784257Smillert.Dv LINE_MAX
16878784257Smillert(2048) bytes in length.
169