# join part.001 and part.002 and part.003



## mfaridi (Jul 21, 2009)

I download big files from internet by torrent and these files are like these


```
part.001 part.002 part.003 and .... part.0035
```
If I use unrar , this packages can not detect this files and say this files are not rar , how I can join them ?
and which packages I can use ?


----------



## SirDice (Jul 21, 2009)

This will do it:
`$  cat part.001 part.002 part.003 > completefile`

But this will get somewhat annoying if you have 30-40 parts. To get around it I wrote a small perl script and called it mpjoin.pl:


```
#!/usr/bin/perl

use FileHandle;
use DirHandle;

my $arg = $ARGV[0] || die "Need an argument!\n";

if( $arg =~ m/(.*)\.\d{2,3}$/ ) { $arg = $1; }

my $dir = DirHandle->new(".");

my $fn, @files;

while( defined( $_ = $dir->read() ) ) {
        next if -d $_;
        next unless m/\Q$arg\E\.\d{2,3}$/;
        push( @files, $_ );
}

if( $#files == 0 ) {
        print "Didn't find any parts\n";
        exit(0);
}

my $of = FileHandle->new("$arg","w");

foreach $fn (sort @files) {
        print "$fn:";
        if( $fn =~ m/.*\.000$/ ) {
                print "Skipping\n";
                next;
        }

        my $if = FileHandle->new("$fn","r");
        while( ! $if->eof() ) {
                my $temp = $if->getline();
                print $of $temp;
        }
        print "Added\n";
}

$of->close();
```

Just call it like `$ mpjoin.pl somefile` and it will join somefile.001, somefile.002 etc. and save it as somefile.


----------



## vermaden (Jul 21, 2009)

SirDice said:
			
		

> This will do it:
> `$  cat part.001 part.002 part.003 > completefile`
> 
> But this will get somewhat annoying if you have 30-40 parts.



What about that?
`$  cat part.* > completefile`


----------



## SirDice (Jul 21, 2009)

vermaden said:
			
		

> What about that?
> `$  cat part.* > completefile`



You can't be sure of the order


----------



## vermaden (Jul 21, 2009)

SirDice said:
			
		

> You can't be sure of the order





```
% :> part.005
% :> part.002
% :> part.004
% :> part.003
% :> part.001
% echo part.*
part.001 part.002 part.003 part.004 part.005
%
```

... yes you can.


----------



## DutchDaemon (Jul 21, 2009)

As long as the 'part generator' plays nicely .. sure. But do they all?


```
echo part.*
part.0 part.1 part.10 part.11 part.12 part.13 part.14 part.15 part.16 part.17 part.18 part.19 part.2 part.20 part.21 part.3 part.4 part.5 part.6 part.7 part.8 part.9
```


----------



## SirDice (Jul 21, 2009)

Well.. I did have problems with filename globbing. Not sure what it was but it was the reason I wrote the script. I think one of the problems was with a large amount of file parts.


----------



## mfaridi (Jul 21, 2009)

if these file is AVI , dose this method work ?


----------



## Djn (Jul 21, 2009)

It will work regardless of the content, if the file is just split cleanly in chunks.


----------



## SirDice (Jul 21, 2009)

mfaridi said:
			
		

> if these file is AVI , dose this method work ?



As long as it's split up with those .001, .002, .003 extensions.

You cannot cat 2 avis together like mymovie-cd1.avi and mymovie-cd2.avi. You could but the indexing will get screwed up. If you want to concatenate 2 (or more) parts like that use mencoder.

`$ mencoder -forceidx -ovc copy -oac copy -o mymovie.avi mymovie-cd1.avi mymovie-cd2.avi`


----------



## mfaridi (Jul 21, 2009)

all of these file is movie , this movie splite part.001 and part.002 and ...
in windows we can use program to join them


----------



## SirDice (Jul 21, 2009)

mfaridi said:
			
		

> all of these file is movie , this movie splite part.001 and part.002 and ...
> in windows we can use program to join them



In that case use my script or cat part.* > output.


----------



## Djn (Jul 21, 2009)

I suggest you try - it sounds like they have just been chunked (the first MB in one file, the next MB in the next file, or whatever size the parts are), and that's exactly what cat was meant to reverse.


----------



## fronclynne (Jun 24, 2010)

Or use sysutils/lxsplit.

(I'm going to take a wild stab that there's some scraps of metadata associated with those files, but I can't warrant so.)


----------

