2015年4月9日 星期四

Linux: Split A File Into Several Smaller Pieces

Split the "BIGFILE" into PREFIX001, PREFIX002, ..., PREFIXNNN files, and each file size is 1MB:
$ split -a 3 -b 1M -d BIGFILE PREFIX
  -a: use suffixes of length N (default 2)
  -b: put SIZE bytes per output file
       SIZE may have a multiplier suffix: b 512, kB 1000, K 1024,
       MB 1000*1000, M 1024*1024, GB 1000*1000*1000,
       G 1024*1024*1024, and so on for T, P, E, Z, Y.
  -d: use numeric suffixes instead of alphabetic

Split a text (log) file into several smaller files, and each one has 1000 lines:
$ split -a 3 -l 1000 -d LOGFILE PREFIX
  -l: put NUMBER lines per output file

Split a text (log) file into several smaller files, and each file size is at most 1MB:
$ split -a 3 -C 1M -d LOGFILE PREFIX
  -C: put at most SIZE bytes of lines per output file

Merge all split files into one:
$ cat PREFIX* > BIGFILE

沒有留言:

張貼留言