View | Details | Raw Unified | Return to bug 269521
Collapse All | Expand All

(-)b/usr.bin/split/split.1 (-5 / +18 lines)
Lines 28-34 Link Here
28
.\"	@(#)split.1	8.3 (Berkeley) 4/16/94
28
.\"	@(#)split.1	8.3 (Berkeley) 4/16/94
29
.\" $FreeBSD$
29
.\" $FreeBSD$
30
.\"
30
.\"
31
.Dd October 25, 2022
31
.Dd February 12, 2023
32
.Dt SPLIT 1
32
.Dt SPLIT 1
33
.Os
33
.Os
34
.Sh NAME
34
.Sh NAME
Lines 36-47 Link Here
36
.Nd split a file into pieces
36
.Nd split a file into pieces
37
.Sh SYNOPSIS
37
.Sh SYNOPSIS
38
.Nm
38
.Nm
39
.Fl d
39
.Op Fl cd
40
.Op Fl l Ar line_count
40
.Op Fl l Ar line_count
41
.Op Fl a Ar suffix_length
41
.Op Fl a Ar suffix_length
42
.Op Ar file Op Ar prefix
42
.Op Ar file Op Ar prefix
43
.Nm
43
.Nm
44
.Fl d
44
.Op Fl cd
45
.Fl b Ar byte_count Ns
45
.Fl b Ar byte_count Ns
46
.Oo
46
.Oo
47
.Sm off
47
.Sm off
Lines 51-62 Link Here
51
.Op Fl a Ar suffix_length
51
.Op Fl a Ar suffix_length
52
.Op Ar file Op Ar prefix
52
.Op Ar file Op Ar prefix
53
.Nm
53
.Nm
54
.Fl d
54
.Op Fl cd
55
.Fl n Ar chunk_count
55
.Fl n Ar chunk_count
56
.Op Fl a Ar suffix_length
56
.Op Fl a Ar suffix_length
57
.Op Ar file Op Ar prefix
57
.Op Ar file Op Ar prefix
58
.Nm
58
.Nm
59
.Fl d
59
.Op Fl cd
60
.Fl p Ar pattern
60
.Fl p Ar pattern
61
.Op Fl a Ar suffix_length
61
.Op Fl a Ar suffix_length
62
.Op Ar file Op Ar prefix
62
.Op Ar file Op Ar prefix
Lines 112-117 or Link Here
112
is appended to the number, the file is split into
112
is appended to the number, the file is split into
113
.Ar byte_count
113
.Ar byte_count
114
gigabyte pieces.
114
gigabyte pieces.
115
.It Fl c
116
Continue creating files and do not overwrite existing
117
output files.  
115
.It Fl d
118
.It Fl d
116
Use a numeric suffix instead of a alphabetic suffix.
119
Use a numeric suffix instead of a alphabetic suffix.
117
.It Fl l Ar line_count
120
.It Fl l Ar line_count
Lines 159-164 argument is not specified, the file is split into lexically ordered Link Here
159
files named with the prefix
162
files named with the prefix
160
.Dq Li x
163
.Dq Li x
161
and with suffixes as above.
164
and with suffixes as above.
165
.Pp
166
By default,
167
.Nm
168
will overwrite any existing output files.
169
If the
170
.Fl c
171
flag is specified,
172
.Nm
173
will instead continue to generate output file names
174
until it finds one that does not already exist.
162
.Sh ENVIRONMENT
175
.Sh ENVIRONMENT
163
The
176
The
164
.Ev LANG , LC_ALL , LC_CTYPE
177
.Ev LANG , LC_ALL , LC_CTYPE
(-)b/usr.bin/split/split.c (-5 / +19 lines)
Lines 67-72 static const char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; Link Here
67
67
68
static off_t	 bytecnt;		/* Byte count to split on. */
68
static off_t	 bytecnt;		/* Byte count to split on. */
69
static off_t	 chunks = 0;		/* Chunks count to split into. */
69
static off_t	 chunks = 0;		/* Chunks count to split into. */
70
static bool      clobber = true;        /* Whether to overwrite existing output files. */
70
static long	 numlines;		/* Line count to split on. */
71
static long	 numlines;		/* Line count to split on. */
71
static int	 file_open;		/* If a file open. */
72
static int	 file_open;		/* If a file open. */
72
static int	 ifd = -1, ofd = -1;	/* Input/output file descriptors. */
73
static int	 ifd = -1, ofd = -1;	/* Input/output file descriptors. */
Lines 92-98 main(int argc, char **argv) Link Here
92
	setlocale(LC_ALL, "");
93
	setlocale(LC_ALL, "");
93
94
94
	dflag = false;
95
	dflag = false;
95
	while ((ch = getopt(argc, argv, "0123456789a:b:dl:n:p:")) != -1)
96
	while ((ch = getopt(argc, argv, "0123456789a:b:cdl:n:p:")) != -1)
96
		switch (ch) {
97
		switch (ch) {
97
		case '0': case '1': case '2': case '3': case '4':
98
		case '0': case '1': case '2': case '3': case '4':
98
		case '5': case '6': case '7': case '8': case '9':
99
		case '5': case '6': case '7': case '8': case '9':
Lines 123-128 main(int argc, char **argv) Link Here
123
			if (error == -1)
124
			if (error == -1)
124
				errx(EX_USAGE, "%s: offset too large", optarg);
125
				errx(EX_USAGE, "%s: offset too large", optarg);
125
			break;
126
			break;
127
		case 'c':               /* Continue, don't overwrite output files. */
128
			clobber = false;
129
			break;
126
		case 'd':		/* Decimal suffix */
130
		case 'd':		/* Decimal suffix */
127
			dflag = true;
131
			dflag = true;
128
			break;
132
			break;
Lines 345-350 newfile(void) Link Here
345
	static char *fpnt;
349
	static char *fpnt;
346
	char beg, end;
350
	char beg, end;
347
	int pattlen;
351
	int pattlen;
352
	int flags = O_WRONLY | O_CREAT | O_TRUNC;
353
354
	if (!clobber) {
355
		flags |= O_EXCL;
356
	}
348
357
349
	if (ofd == -1) {
358
	if (ofd == -1) {
350
		if (fname[0] == '\0') {
359
		if (fname[0] == '\0') {
Lines 353-361 newfile(void) Link Here
353
		} else {
362
		} else {
354
			fpnt = fname + strlen(fname);
363
			fpnt = fname + strlen(fname);
355
		}
364
		}
356
		ofd = fileno(stdout);
365
	} else if (close(ofd) != 0)
357
	}
366
		err(1, "%s", fname);
358
367
368
	again:
359
	if (dflag) {
369
	if (dflag) {
360
		beg = '0';
370
		beg = '0';
361
		end = '9';
371
		end = '9';
Lines 386-393 newfile(void) Link Here
386
	fpnt[sufflen] = '\0';
396
	fpnt[sufflen] = '\0';
387
397
388
	++fnum;
398
	++fnum;
389
	if (!freopen(fname, "w", stdout))
399
	if ((ofd = open(fname, flags, DEFFILEMODE)) < 0) {
400
		if (!clobber && errno == EEXIST) {
401
			goto again;
402
		}
390
		err(EX_IOERR, "%s", fname);
403
		err(EX_IOERR, "%s", fname);
404
	}
391
	file_open = 1;
405
	file_open = 1;
392
}
406
}
393
407
Lines 395-401 static void Link Here
395
usage(void)
409
usage(void)
396
{
410
{
397
	(void)fprintf(stderr,
411
	(void)fprintf(stderr,
398
"usage: split [-l line_count] [-a suffix_length] [file [prefix]]\n"
412
"usage: split [-c] [-l line_count] [-a suffix_length] [file [prefix]]\n"
399
"       split -b byte_count[K|k|M|m|G|g] [-a suffix_length] [file [prefix]]\n"
413
"       split -b byte_count[K|k|M|m|G|g] [-a suffix_length] [file [prefix]]\n"
400
"       split -n chunk_count [-a suffix_length] [file [prefix]]\n"
414
"       split -n chunk_count [-a suffix_length] [file [prefix]]\n"
401
"       split -p pattern [-a suffix_length] [file [prefix]]\n");
415
"       split -p pattern [-a suffix_length] [file [prefix]]\n");

Return to bug 269521