Make a hash of array keyed upon the "number" of the file (the digits before the '.' or '_').
Then for each new numbered "append" file, open a file handle and copy the files to the new file.
#!/usr/bin/perl -w use strict; my %new_files; while (my $filename = <DATA>) { chomp $filename; my $num = ($filename =~ /^(\d+)/)[0]; #just the first digits push (@{$new_files{$num}},$filename); } foreach my $new_file (keys %new_files) { print "open file for ....$new_file"."_AppendFile.txt\n"; #your code print "put these files in there: \n"; #you have to make a copy loop print "@{$new_files{$new_file}}", "\n"; print "\n"; } =prints: open file for ....1_AppendFile.txt put these files in there: 1_ABC.txt 1_XYZ.txt open file for ....3_AppendFile.txt put these files in there: 3_ABC.txt open file for ....2_AppendFile.txt put these files in there: 2_ABC.txt 2.XYZ.txt open file for ....5_AppendFile.txt put these files in there: 5.XYZ.txt =cut __DATA__ 1_ABC.txt 2_ABC.txt 3_ABC.txt 1_XYZ.txt 2.XYZ.txt 5.XYZ.txt
In reply to Re: Appending multiple files into one or more files
by Marshall
in thread Appending multiple files into one or more files
by iamravikanth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |