xref: /freebsd/usr.bin/csplit/csplit.1 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1ea9e961cSTim J. Robbins.\" Copyright (c) 2002 Tim J. Robbins.
2ea9e961cSTim J. Robbins.\" All rights reserved.
3ea9e961cSTim J. Robbins.\"
4ea9e961cSTim J. Robbins.\" Redistribution and use in source and binary forms, with or without
5ea9e961cSTim J. Robbins.\" modification, are permitted provided that the following conditions
6ea9e961cSTim J. Robbins.\" are met:
7ea9e961cSTim J. Robbins.\" 1. Redistributions of source code must retain the above copyright
8ea9e961cSTim J. Robbins.\"    notice, this list of conditions and the following disclaimer.
9ea9e961cSTim J. Robbins.\" 2. Redistributions in binary form must reproduce the above copyright
10ea9e961cSTim J. Robbins.\"    notice, this list of conditions and the following disclaimer in the
11ea9e961cSTim J. Robbins.\"    documentation and/or other materials provided with the distribution.
12ea9e961cSTim J. Robbins.\"
13ea9e961cSTim J. Robbins.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ea9e961cSTim J. Robbins.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ea9e961cSTim J. Robbins.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ea9e961cSTim J. Robbins.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17ea9e961cSTim J. Robbins.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ea9e961cSTim J. Robbins.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ea9e961cSTim J. Robbins.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ea9e961cSTim J. Robbins.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ea9e961cSTim J. Robbins.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ea9e961cSTim J. Robbins.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ea9e961cSTim J. Robbins.\" SUCH DAMAGE.
24ea9e961cSTim J. Robbins.\"
25*3d9335a6SJoel Dahl.Dd February 6, 2014
26ea9e961cSTim J. Robbins.Dt CSPLIT 1
27ea9e961cSTim J. Robbins.Os
28ea9e961cSTim J. Robbins.Sh NAME
29ea9e961cSTim J. Robbins.Nm csplit
30ea9e961cSTim J. Robbins.Nd split files based on context
31ea9e961cSTim J. Robbins.Sh SYNOPSIS
32ea9e961cSTim J. Robbins.Nm
33ea9e961cSTim J. Robbins.Op Fl ks
34ea9e961cSTim J. Robbins.Op Fl f Ar prefix
35ea9e961cSTim J. Robbins.Op Fl n Ar number
362d2ca466SRuslan Ermilov.Ar file args ...
37ea9e961cSTim J. Robbins.Sh DESCRIPTION
38ea9e961cSTim J. RobbinsThe
39ea9e961cSTim J. Robbins.Nm
40ea9e961cSTim J. Robbinsutility splits
41ea9e961cSTim J. Robbins.Ar file
42ea9e961cSTim J. Robbinsinto pieces using the patterns
432d2ca466SRuslan Ermilov.Ar args .
44ea9e961cSTim J. RobbinsIf
45ea9e961cSTim J. Robbins.Ar file
46ea9e961cSTim J. Robbinsis
47ea9e961cSTim J. Robbinsa dash
482d2ca466SRuslan Ermilov.Pq Sq Fl ,
49ea9e961cSTim J. Robbins.Nm
50ea9e961cSTim J. Robbinsreads from standard input.
51ea9e961cSTim J. Robbins.Pp
52514262ddSTom RhodesFiles are created with a prefix of
53514262ddSTom Rhodes.Dq xx
54514262ddSTom Rhodesand two decimal digits.
55514262ddSTom RhodesThe size of each file is written to standard output
56514262ddSTom Rhodesas it is created.
57514262ddSTom RhodesIf an error occurs whilst files are being created,
58514262ddSTom Rhodesor a
59514262ddSTom Rhodes.Dv HUP ,
60514262ddSTom Rhodes.Dv INT ,
61514262ddSTom Rhodesor
62514262ddSTom Rhodes.Dv TERM
63514262ddSTom Rhodessignal is received,
64514262ddSTom Rhodesall files previously written are removed.
65514262ddSTom Rhodes.Pp
66ea9e961cSTim J. RobbinsThe options are as follows:
67ea9e961cSTim J. Robbins.Bl -tag -width indent
68ea9e961cSTim J. Robbins.It Fl f Ar prefix
69514262ddSTom RhodesCreate file names beginning with
70514262ddSTom Rhodes.Ar prefix ,
71514262ddSTom Rhodesinstead of
722d2ca466SRuslan Ermilov.Dq Pa xx .
73ea9e961cSTim J. Robbins.It Fl k
74514262ddSTom RhodesDo not remove previously created files if an error occurs or a
75514262ddSTom Rhodes.Dv HUP ,
76514262ddSTom Rhodes.Dv INT ,
77514262ddSTom Rhodesor
78514262ddSTom Rhodes.Dv TERM
79514262ddSTom Rhodessignal is received.
80ea9e961cSTim J. Robbins.It Fl n Ar number
81514262ddSTom RhodesCreate file names beginning with
82ea9e961cSTim J. Robbins.Ar number
83514262ddSTom Rhodesof decimal digits after the prefix,
84514262ddSTom Rhodesinstead of 2.
85ea9e961cSTim J. Robbins.It Fl s
86ea9e961cSTim J. RobbinsDo not write the size of each output file to standard output as it is
87ea9e961cSTim J. Robbinscreated.
88ea9e961cSTim J. Robbins.El
89ea9e961cSTim J. Robbins.Pp
90ea9e961cSTim J. RobbinsThe
912d2ca466SRuslan Ermilov.Ar args
92ea9e961cSTim J. Robbinsoperands may be a combination of the following patterns:
932d2ca466SRuslan Ermilov.Bl -tag -width indent
942d2ca466SRuslan Ermilov.It Xo
952d2ca466SRuslan Ermilov.Sm off
962d2ca466SRuslan Ermilov.Cm / Ar regexp Cm / Op Oo Cm + | - Oc Ar offset
972d2ca466SRuslan Ermilov.Sm on
982d2ca466SRuslan Ermilov.Xc
99ea9e961cSTim J. RobbinsCreate a file containing the input from the current line to (but not including)
100ea9e961cSTim J. Robbinsthe next line matching the given basic regular expression.
101ea9e961cSTim J. RobbinsAn optional
102ea9e961cSTim J. Robbins.Ar offset
103ea9e961cSTim J. Robbinsfrom the line that matched may be specified.
1042d2ca466SRuslan Ermilov.It Xo
1052d2ca466SRuslan Ermilov.Sm off
1062d2ca466SRuslan Ermilov.Cm % Ar regexp Cm % Op Oo Cm + | - Oc Ar offset
1072d2ca466SRuslan Ermilov.Sm on
1082d2ca466SRuslan Ermilov.Xc
109ea9e961cSTim J. RobbinsSame as above but a file is not created for the output.
110ea9e961cSTim J. Robbins.It Ar line_no
111ea9e961cSTim J. RobbinsCreate containing the input from the current line to (but not including)
112ea9e961cSTim J. Robbinsthe specified line number.
113ea9e961cSTim J. Robbins.It Cm { Ns Ar num Ns Cm }
114ea9e961cSTim J. RobbinsRepeat the previous pattern the specified number of times.
115ea9e961cSTim J. RobbinsIf it follows a line number pattern, a new file will be created for each
1162d2ca466SRuslan Ermilov.Ar line_no
117ea9e961cSTim J. Robbinslines,
1182d2ca466SRuslan Ermilov.Ar num
119ea9e961cSTim J. Robbinstimes.
120ea9e961cSTim J. RobbinsThe first line of the file is line number 1 for historic reasons.
121ea9e961cSTim J. Robbins.El
122ea9e961cSTim J. Robbins.Pp
123ea9e961cSTim J. RobbinsAfter all the patterns have been processed, the remaining input data
124ea9e961cSTim J. Robbins(if there is any) will be written to a new file.
125ea9e961cSTim J. Robbins.Pp
126ea9e961cSTim J. RobbinsRequesting to split at a line before the current line number or past the
127ea9e961cSTim J. Robbinsend of the file will result in an error.
1289bd2f93aSTim J. Robbins.Sh ENVIRONMENT
1299bd2f93aSTim J. RobbinsThe
13093df2494SRuslan Ermilov.Ev LANG , LC_ALL , LC_COLLATE
1319bd2f93aSTim J. Robbinsand
1329bd2f93aSTim J. Robbins.Ev LC_CTYPE
1339bd2f93aSTim J. Robbinsenvironment variables affect the execution of
1349bd2f93aSTim J. Robbins.Nm
1359bd2f93aSTim J. Robbinsas described in
1369bd2f93aSTim J. Robbins.Xr environ 7 .
1376c7216dfSRuslan Ermilov.Sh EXIT STATUS
1386c7216dfSRuslan Ermilov.Ex -std
139ea9e961cSTim J. Robbins.Sh EXAMPLES
140ea9e961cSTim J. RobbinsSplit the
141ea9e961cSTim J. Robbins.Xr mdoc 7
142ea9e961cSTim J. Robbinsfile
143ea9e961cSTim J. Robbins.Pa foo.1
144*3d9335a6SJoel Dahlinto one file for each section (up to 21 plus one for the rest, if any):
145ea9e961cSTim J. Robbins.Pp
1462d2ca466SRuslan Ermilov.Dl "csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'"
147ea9e961cSTim J. Robbins.Pp
148ea9e961cSTim J. RobbinsSplit standard input after the first 99 lines and every 100 lines thereafter:
149ea9e961cSTim J. Robbins.Pp
1502d2ca466SRuslan Ermilov.Dl "csplit -k - 100 '{19}'"
151ea9e961cSTim J. Robbins.Sh SEE ALSO
152ea9e961cSTim J. Robbins.Xr sed 1 ,
153ea9e961cSTim J. Robbins.Xr split 1 ,
154ea9e961cSTim J. Robbins.Xr re_format 7
155ea9e961cSTim J. Robbins.Sh STANDARDS
156ea9e961cSTim J. RobbinsThe
157ea9e961cSTim J. Robbins.Nm
158ea9e961cSTim J. Robbinsutility conforms to
159ea9e961cSTim J. Robbins.St -p1003.1-2001 .
1606c7216dfSRuslan Ermilov.Sh HISTORY
1616c7216dfSRuslan ErmilovA
1626c7216dfSRuslan Ermilov.Nm
1636c7216dfSRuslan Ermilovcommand appeared in PWB UNIX.
164d99e9276STim J. Robbins.Sh BUGS
165d99e9276STim J. RobbinsInput lines are limited to
166d99e9276STim J. Robbins.Dv LINE_MAX
167d99e9276STim J. Robbins(2048) bytes in length.
168