a9af66cd85aeed6cd3232460fae221559cea25f6
[dragonfly.git] / usr.bin / csplit / csplit.1
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: src/usr.bin/csplit/csplit.1,v 1.6 2002/08/14 11:38:30 ru Exp $
26 .\" $DragonFly: src/usr.bin/csplit/csplit.1,v 1.3 2007/07/30 22:11:33 swildner Exp $
27 .\"
28 .Dd June 19, 2004
29 .Dt CSPLIT 1
30 .Os
31 .Sh NAME
32 .Nm csplit
33 .Nd split files based on context
34 .Sh SYNOPSIS
35 .Nm
36 .Op Fl ks
37 .Op Fl f Ar prefix
38 .Op Fl n Ar number
39 .Ar file args ...
40 .Sh DESCRIPTION
41 The
42 .Nm
43 utility splits
44 .Ar file
45 into pieces using the patterns
46 .Ar args .
47 If
48 .Ar file
49 is
50 a dash
51 .Pq Sq Fl ,
52 .Nm
53 reads from standard input.
54 .Pp
55 The options are as follows:
56 .Bl -tag -width indent
57 .It Fl f Ar prefix
58 Give created files names beginning with
59 .Ar prefix .
60 The default is
61 .Dq Pa xx .
62 .It Fl k
63 Do not remove output files if an error occurs or a
64 .Dv HUP ,
65 .Dv INT
66 or
67 .Dv TERM
68 signal is received.
69 .It Fl n Ar number
70 Use
71 .Ar number
72 of decimal digits after the
73 .Ar prefix
74 to form the file name.
75 The default is 2.
76 .It Fl s
77 Do not write the size of each output file to standard output as it is
78 created.
79 .El
80 .Pp
81 The
82 .Ar args
83 operands may be a combination of the following patterns:
84 .Bl -tag -width indent
85 .It Xo
86 .Sm off
87 .Cm / Ar regexp Cm / Op Oo Cm + | - Oc Ar offset
88 .Sm on
89 .Xc
90 Create a file containing the input from the current line to (but not including)
91 the next line matching the given basic regular expression.
92 An optional
93 .Ar offset
94 from the line that matched may be specified.
95 .It Xo
96 .Sm off
97 .Cm % Ar regexp Cm % Op Oo Cm + | - Oc Ar offset
98 .Sm on
99 .Xc
100 Same as above but a file is not created for the output.
101 .It Ar line_no
102 Create containing the input from the current line to (but not including)
103 the specified line number.
104 .It Cm { Ns Ar num Ns Cm }
105 Repeat the previous pattern the specified number of times.
106 If it follows a line number pattern, a new file will be created for each
107 .Ar line_no
108 lines,
109 .Ar num
110 times.
111 The first line of the file is line number 1 for historic reasons.
112 .El
113 .Pp
114 After all the patterns have been processed, the remaining input data
115 (if there is any) will be written to a new file.
116 .Pp
117 Requesting to split at a line before the current line number or past the
118 end of the file will result in an error.
119 .Sh ENVIRONMENT
120 The
121 .Ev LANG , LC_ALL , LC_COLLATE
122 and
123 .Ev LC_CTYPE
124 environment variables affect the execution of
125 .Nm
126 as described in
127 .Xr environ 7 .
128 .Sh EXAMPLES
129 Split the
130 .Xr mdoc 7
131 file
132 .Pa foo.1
133 into one file for each section (up to 20):
134 .Pp
135 .Dl "csplit -k foo.1 '%^\e.Sh%' '/^\e.Sh/' '{20}'"
136 .Pp
137 Split standard input after the first 99 lines and every 100 lines thereafter:
138 .Pp
139 .Dl "csplit -k - 100 '{19}'"
140 .Sh DIAGNOSTICS
141 .Ex -std
142 .Sh SEE ALSO
143 .Xr sed 1 ,
144 .Xr split 1 ,
145 .Xr re_format 7
146 .Sh STANDARDS
147 The
148 .Nm
149 utility conforms to
150 .St -p1003.1-2001 .
151 .Sh HISTORY
152 A
153 .Nm
154 command appeared in PWB
155 .Ux .
156 .Sh AUTHORS
157 The
158 .Nm
159 utility was written by
160 .An Tim J\. Robbins Aq tjr@FreeBSD.org .