How To Split Big File into Smaller Files in Unix


                                      


split command is used to split large files into smaller files in Unix.. Syntax of Split command :

#  split [options]   File name   New file name

Replace “File name” by the name of the file you wish to split or we can say whose size is large. Replace “New file name” with the name you want to give output files of small size.
In place of [options], you can use following:

-l  linenumber
-b bytes

If we use -l (lowercase L) in place of option, than it signifies the number of lines you like in each of the smaller size files (by default it is 1,000).

If you use the -b option in place of option, than it signifies the number of bytes you like in each of the smaller size files.

The split command will give output file of “New file name” and add some letters that indicate its order. By default, the split command add “aa” to the first output file, proceeding by the alphabet to” zz” for subsequent files. If you do not specify a “New file name” most systems use x.

Examples :
·         In this simple example, assume workfile is 4,000 lines long:

# split workfile

This will output four 1000-line files: xaa, xab, xac and xad.

·         Working on the same file, this next example is little complex:

# split -l 500 workfile outputfile

This will output eight 500-line files: outputfileaa, outputfileab, outputfileac, outputfilead, outputfileae, outputfileaf, outputfileag and outputfileah.
  
·         Finally, assume workfile is a 120KB file:   

#  split -b 40k   workfile outputfile

This will output three 40KB files: outputfileaa, outputfileab, and outputfileac.