Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used split -b 32m "file.bz2" "file.bz2.part-" to split a file and it created more than 50 parts. From googling, the way I found to reassemble the parts is to cat file.bz2.part-aa file.bz2.part-ab > file.bz2, while enumerating all the 50+ parts. Is there an easier way to reassemble the parts wherein I no longer need to list all those parts explicitly?

I'm using Fedora 12.

share|improve this question

3 Answers 3

up vote 7 down vote accepted

This is what wildcards and brace expansion are for. See if echo file.bz2.part-* returns the filenames in the desired order, and use cat file.bz2.part-* > file.bz2 if it does. Otherwise, figure out some other more complex expansion that does.

share|improve this answer
1  
+1 and a "Useful use of cat" award. in-ulm.de/~mascheck/various/uuoc –  coneslayer Apr 13 '10 at 1:08

Try:

for i in `ls file.part-* |sort`; do echo $i; cat $i >> newfile; done
share|improve this answer
    
the back ticks were stripped off. add a back tick in front of ls and to the right of sort. –  stuart Oct 22 '10 at 1:51
1  
Fixed, the back ticks are added back as they were intended. –  8088 Jul 2 '11 at 5:32

split creates its partial file names in ascending lexicographical order. Since wildcard expansions lists the files in lexicographical order, cat file.bz2part-* > file.bz2 will concatenate the parts in the right order.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.