[Previous] [Contents] [Index] [Next]

split

Split files into pieces (POSIX)

Syntax:

split [-a suffix_length] [-b n[k|m]] [-l line_count]
      [-p pattern] [file [name]]

Options:

-a suffix_length
Use suffix_length letters to form the suffix of the filenames of the split file.
-b n[k|m]
Split a file into pieces that are n bytes in size. You can add the letter k or m after n to specify units of kilobytes (1024 bytes) or megabytes (1048576 bytes).
-l line_count
("el")Split the files so that there are line_count lines in each resulting file piece. The line_count argument is an unsigned decimal integer. The default is 1000. Note that the last file might differ in size from the other files.
-p pattern
(non-POSIX extension) Split the file whenever an input line matches pattern, which is interpreted as an extended regular expression. The matching line will be the first line of the next output file. Note that this option is incompatible with the -b and -l options.
file
The pathname of the file to be split. If you don't specify any files, or file is -, split reads from standard input.
name
The prefix to be used for each of the files resulting from the split operation. If you don't specify a name, x is used as the prefix of the output files. The combined length of name and suffix_length can't exceed 48 characters.

Description:

The split utility reads an input file and writes the data from that file into one or more output files.

By default, the names of the output files are xaa, xab, ..., xzz, and each output file, except possibly the last, gets 1000 lines.

The last file contains the remainder of the input file, and therefore may be smaller than the requested size. Conversely, it may be longer than the other files if there are too few filenames available to take all the input in chunks of the specified size.

Examples:

Suppose you have a file named big_file that's 8192 lines in length. The following command creates nine files named xaa, xab, xac, ..., xai. The first eight files all contain 1000 lines, while the last file contains only 192:

split big_file

Again, assuming that big_file is 8192 lines in length, the following command creates only two files: smaller_aa, which contains 8000 lines, and smaller_ab, which contains 192 lines:

split -l 8000 big_file smaller_

Files:

You can use any file as input, but if you're splitting a nontext file, you must specify option -b. The output files contain portions of the original input file that are otherwise unchanged.

Exit status:

0
Successful completion.
>0
An error occurred.

See also:

awk, cat, cut, head, sed, tail


[Previous] [Contents] [Index] [Next]