Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have lots of files eg.

a.xxx.001 a.xxx.002

b.yyy.001 b.yyy.002 b.yyy.003

How can I merge then into: a.xxx and b.yyy? In Ubuntu

share|improve this question

2 Answers 2

Assuming the original file was straightforwardly split into chunks (so the chunks don't have headers or anything like that), use the concatenate command:

cat a.xxx.??? >a.xxx

Make sure that you have all the pieces, since cat will just concatenate what it's given. If your shell is bash (the default shell) or zsh, you can use

cat a.xxx.{001..002} >a.xxx
cat b.yyy.{001..003} >b.yyy

This way, cat is given the names of the expected pieces in order, so you will get an error message if any of the pieces is missing.

share|improve this answer
    
Assuming that the current working directory contains only those pieces, he can also use cat a.xxx.* > cat a.xxx. –  Cristian Ciupitu Sep 18 '10 at 12:45
1  
@Cristian: I didn't use * because it's more failure-prone. If the pieces are called …, a.xxx.9, a.xxx.10, …, it's obvious that .??? won't work, whereas .* would silently concatenate the pieces in the wrong order. .??? is also a little more robust against stray files being caught, though .[0-9][0-9][0-9] would be safer (but would require significantly more typing). –  Gilles Sep 18 '10 at 13:48
    
@Giles: a good split program would use proper file names for the pieces to avoid this issue. –  Cristian Ciupitu Sep 18 '10 at 20:01
$ cat a.xxx.001 a.xxx.002 > a.xxx
$ cat b.yyy.001 b.yyy.002 b.yyy.003 > b.xxx
share|improve this answer
    
Your idea is good, but he said that he has lots of files, not only a couple of files. –  Cristian Ciupitu Sep 18 '10 at 12:43
    
Not sure how the previous comment relates; both answers do it well, but you should definitely be using wild cards instead of explicitly listing them. –  Andrew M. Sep 18 '10 at 13:11
    
True. The answer below is better. Btw, to do it on modification date, something like "cat ls -tr a.xxx.* > a.xxx" would work. –  Wouter de Bie Sep 18 '10 at 14:28
    
@Redmumba: yeah, I was referring to wildcards. –  Cristian Ciupitu Sep 18 '10 at 15:43

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.