in reply to compare and merge files

The actual file joining would be easier with the (unix) shell (or the windows equivalent of same, available from cygwin, ATT Research Labs, etc):
cat /some/full/path/file.abc.part*.txt > /some/full/path/file.abc.MERG +ED.txt
Although that could go haywire if the sequencing is important and the file names don't sort "naturally" into the correct order -- e.g. if you have names like:
file.abc.part-1.txt file.abc.part-10.txt file.abc.part-11.txt file.abc.part-2.txt file.abc.part-3.txt ...
If that's how the file names go, you'll want to use Perl to sort things properly. How about:
#!/usr/bin/perl use strict; die "Usage: $0 /full/path/to/data/dir\n" unless ( @ARGV == 1 and -d $ARGV[0] ); my $basedir = shift; chdir $basedir or die "chdir $basedir failed: $!"; my @parts = <*.part-*.txt>; # or: # opendir D, "."; # my @parts = grep /\.part-\d+\./, readdir D; # closedir D; my %merged; for my $part ( sort { my ($x) = ($a=~/part-(\d+)/); my ($y) = ($b=~/part-(\d+)/); $x <=> $y } @parts ) { my ( $merge_key ) = ( $part =~ /^(.*)\.part-\d/ ); push @{$merged{$merge_key}}, $part; } for my $mrgfile ( sort keys %merged ) { open( OUT, ">", "$mrgfile.MERGED.txt" ) or die "$mrgfile.MERGED.txt: $!"; local $/; for my $partfile ( @{$merged{$mrgfile}} ) { $_ = do { open( I, $partfile ); <I> } close I; print OUT; } close OUT; }
(not tested, but should be pretty close to what you want)

Replies are listed 'Best First'.
Re^2: compare and merge files
by Fletch (Bishop) on Feb 05, 2006 at 18:59 UTC

    Really even then you can still stick to the shell, it's just a little trickier . . .

    $ /bin/ls foo-*.txt | sort -n -t - +1 -2 foo-1.txt foo-2.txt foo-3.txt foo-4.txt foo-5.txt foo-6.txt foo-7.txt foo-8.txt foo-9.txt foo-10.txt foo-11.txt