#!/usr/bin/perl use strict; use warnings; open my $input, '<' or die "Unable to open input file: $!"; my @file = <$input>; my @sorted_file = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { my ($x) = $_ =~ /VerNumber:\((\d+)/i; [$_, $x]; } @file; open my $output, '>' or die "Unable to open output file: $!"; print $output $_ for @sorted_file; #### file1.txt file2.txt ... file1000.txt #### /sorted file1.txt -> /sorted/file1.txt file2.txt -> /sorted/file2.txt ... file1000.txt -> /sorted/file1000.txt #### #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $version="0.2"; my $files_match=""; my $files_dir=""; my $file_name=""; my $help_flag=""; my $version_flag=""; GetOptions( 'm|match=s' => \$files_match, 'd|directory=s' => \$files_dir, 'h|help' => \$help_flag, 'v|version' => \$version_flag, ); sub sorting { my @file = "$_"; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { my ($x) = $_ =~ /VerNumber:\((\d+)/i; [$_, $x]; } @file; print FILE $_; } if (($files_match ne "") and ($files_dir ne "")) { chdir("$files_dir") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = grep {/$files_match/} readdir DIR; my $files_size = $#files + 1; my $index_file = 1; print "Files to process: $files_size\n"; close DIR; foreach (@files) { open(FILE, ">./sorted/$_.sort") or die $!; my @singlefile = $_; print "Processing $index_file of $files_size files: $_\n"; local @ARGV = @singlefile; while(<>){ sorting($_); } close(FILE); $index_file++; print "OK: Sorted @singlefile \n"; } } elsif ((!$help_flag) and (!$version_flag)){printHelp();}