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.

link|improve this question

71% accept rate
feedback

3 Answers

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.

link|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
feedback

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.

link|improve this answer
feedback

Try:

for i in `ls file.part-* |sort`; do echo $i; cat $i >> newfile; done
link|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
Fixed, the back ticks are added back as they were intended. – Gareth Jul 2 '11 at 5:32
feedback

Your Answer

 
or
required, but never shown

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