[Previous] [Contents] [Next]

split

Split files into pieces (POSIX)

Syntax:

split [-[l] line_count] [-a suffix_length] [file [name]]

split -b n[k|m] [-a suffix_length] [file [name]]

Options:

-a suffix_length
Use suffix_length letters to form the suffix portion of the filenames of the split file. The default suffix length is two characters.
-b n[k|m]
Split a file into pieces that are n bytes in size. The letters k or m may be added after n to specify units of kilobytes (1024 bytes) or megabytes (1048576 bytes), respectively.
-[l] line_count
Split the files so that there are line_count lines in each resulting file piece. The l ("el") is optional (e.g. -50 is equivalent to -l 50), but the l should be specified since -nn is an obsolescent syntax. 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.
file
The pathname of the file to be split. If no files are specified or file is -, the standard input is used.
name
The prefix to be used for each of the files resulting from the split operation. If name isn't given, 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 will contain 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 will create nine files named xaa, xab, xac, ..., xai. The first eight files will all contain 1000 lines, while the last file will contain only 192.

    split big_file

The following command will produce files similar to those above, except the output filenames will consist of a three-letter suffix (i.e. xaaa, xaab, xaac, and so on):

    split -a 3 big_file

Again, assuming that big_file is 8192 lines in length, the following command will create only two files: smaller_aa, which will contain 8000 lines, and smaller_ab, which will contain 192 lines.

    split -l 8000 big_file smaller_

Files:

You can use any file as input, but if you're splitting a non-text 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] [Next]