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)

In reply to Re: compare and merge files by graff
in thread compare and merge files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.