Tuesday, 13 March 2018

Split large files into a number of smaller files in Unix



To split large files into smaller files in Unix, use the split command. At the Unix prompt, enter:
  split [options] filename prefix
Replace filename with the name of the large file you wish to split. Replace prefix with the name you wish to give the small output files. You can exclude [options], or replace it with either of the following:
  -l linenumber

  -b bytes


  • n this simple example, assume myfile is 3,000 lines long:
      split samplefile
    This will output three 1000-line files: xaaxab, and xac.
  • Working on the same file, this next example is more complex:
      split -l 500 samplefile segment
    This will output six 500-line files: segmentaasegmentabsegmentacsegmentadsegmentae, andsegmentaf.
  • Finally, assume samplefile is a 160KB file:
      split -b 40k samplefile segment

1 comment: