[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 5


split Command

Purpose

Splits a file into pieces.

Syntax

To Split a File Into Multiple Files Containing a Specified Number of Lines

split-l LineCount ] [ -a SuffixLength ] [ File Prefix ] ]

To Split a File Into Multiple Files Containing a Specified Number of Bytes

split -b Number [ m ] [ -a SuffixLength ] [ File Prefix ] ]

Description

The split command reads the specified file and writes it in 1000-line pieces to a set of output files. The name of the first output file is constructed by combining the specified prefix (x by default) with the aa suffix, the second by combining the prefix with the ab suffix, and so on lexicographically through zz (a maximum of 676 files). The number of letters in the suffix, and consequently the number of output name files, can be increased by using the -a flag.

You cannot specify a Prefix longer than PATH_MAX - 2 bytes (or PATH_MAX - SuffixLength bytes if the -a flag is specified). The PATH_MAX variable specifies the maximum path-name length for the system as defined in the /usr/include/sys/limits.h file.

If you do not specify an input file or if you specify a file name of - (minus sign), the split command reads standard input.

Flags

Note: The -b and -l flags are mutually exclusive.

-a SuffixLength Specifies the number of letters to use in forming the suffix portion of the output name files. The number of letters determines the number of possible output filename combinations. The default is two letters.
-b Number Splits the file into the number of bytes specified by the Number variable. Adding the k (kilobyte) or m (megabyte) multipliers to the end of the Number value causes the file to be split into Number*1024 or Number*1,048,576 byte pieces, respectively.
-l LineCount Specifies the number of lines in each output file. The default is 1000 lines.

Exit Status

This command returns the following exit values:

0 The command ran successfully.
>0 An error occurred.

Examples

  1. To split a file into 1000-line segments, enter:

    split book
    

    This example splits book into 1000-line segments named xaaxabxac, and so forth.

  2. To split a file into 50-line segments and specify the file-name prefix, enter:

    split -l 50 book sect
    

    This example splits book into 50-line segments named sectaa, sectab, sectac, and so forth.

  3. To split a file into 2KB segments, enter:

    split -b 2k book
    

    This example splits the book into 2*1024-byte segments named xaa, xab, xac, and so forth.

  4. To split a file into more than 676 segments, enter:

    split -l 5 -a 3 book sect
    

    This example splits a book into 5-line segments named sectaaa, sectaab, sectaac, and so forth, up to sectzzz (a maximum of 17,576 files).

Files


/usr/bin/split Contains the split command.

Related Information

The csplit command.

Files Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.

Input and Output Redirection Overview in AIX 5L Version 5.1 System User's Guide: Operating System and Devices.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]