Monday, July 27, 2015

cut a big file into many pieces : split

Learn "split" via example: 

1. List the big file
[Deyong.Xu@t10a1 today]$ lr -h  mag_gfs_processor.o751319
-rw-r--r-- 1 Deyong.Xu g02 2.6G Jul 23 18:28 mag_gfs_processor.o751319

2. Split the file into piece of  139018569 bytes. ( 139M bytes / piece )
$ split    -b   139018569   mag_gfs_processor.o751319

3. List all the pieces
$ lr  -h    xa?
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xaa
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xab
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xac
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xad
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xae
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xaf
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xag
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xah
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xai
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xaj
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xak
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xal
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xam
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xan
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xao
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xap
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xaq
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xar
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xas
-rw-r--r-- 1 Deyong.Xu g02  139018569 Jul 27 18:37 xat
-rw-r--r-- 1 Deyong.Xu g02         16 Jul 27 18:37 xau

4. Pieces are named in following order: 
xa[a-z]
xb[a-z]
...
xz[a-z]   (xzz is the last piece you can go, otherwise, you will get "split: output file suffixes exhausted" error.) 

5. Restore file 
$  cat   xaa   xab  xac  >  a_big_file

No comments:

Post a Comment