xref: /freebsd/usr.bin/csplit/csplit.1 (revision 9162f64b58d01ec01481d60b6cdc06ffd8e8c7fc)
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 December 24, 2008
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.
63.It Fl n Ar number
64Use
65.Ar number
66of decimal digits after the
67.Ar prefix
68to form the file name.
69The default is 2.
70.It Fl s
71Do not write the size of each output file to standard output as it is
72created.
73.El
74.Pp
75The
76.Ar args
77operands may be a combination of the following patterns:
78.Bl -tag -width indent
79.It Xo
80.Sm off
81.Cm / Ar regexp Cm / Op Oo Cm + | - Oc Ar offset
82.Sm on
83.Xc
84Create a file containing the input from the current line to (but not including)
85the next line matching the given basic regular expression.
86An optional
87.Ar offset
88from the line that matched may be specified.
89.It Xo
90.Sm off
91.Cm % Ar regexp Cm % Op Oo Cm + | - Oc Ar offset
92.Sm on
93.Xc
94Same as above but a file is not created for the output.
95.It Ar line_no
96Create containing the input from the current line to (but not including)
97the specified line number.
98.It Cm { Ns Ar num Ns Cm }
99Repeat the previous pattern the specified number of times.
100If it follows a line number pattern, a new file will be created for each
101.Ar line_no
102lines,
103.Ar num
104times.
105The first line of the file is line number 1 for historic reasons.
106.El
107.Pp
108After all the patterns have been processed, the remaining input data
109(if there is any) will be written to a new file.
110.Pp
111Requesting to split at a line before the current line number or past the
112end of the file will result in an error.
113.Sh ENVIRONMENT
114The
115.Ev LANG , LC_ALL , LC_COLLATE
116and
117.Ev LC_CTYPE
118environment variables affect the execution of
119.Nm
120as described in
121.Xr environ 7 .
122.Sh EXIT STATUS
123.Ex -std
124.Sh EXAMPLES
125Split the
126.Xr mdoc 7
127file
128.Pa foo.1
129into one file for each section (up to 20):
130.Pp
131.Dl "csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'"
132.Pp
133Split standard input after the first 99 lines and every 100 lines thereafter:
134.Pp
135.Dl "csplit -k - 100 '{19}'"
136.Sh SEE ALSO
137.Xr sed 1 ,
138.Xr split 1 ,
139.Xr re_format 7
140.Sh STANDARDS
141The
142.Nm
143utility conforms to
144.St -p1003.1-2001 .
145.Sh HISTORY
146A
147.Nm
148command appeared in PWB UNIX.
149.Sh BUGS
150Input lines are limited to
151.Dv LINE_MAX
152(2048) bytes in length.
153