Sammeln Sie zuerst die Liste der Bildnamen:
ls *jpg | gawk -F_ '' | sort | uniq
Nun führe sie durch montage
:
ls *jpg | gawk -F_ '' | sort | uniq | while read n; do montage *\_$n\_* IMAGE_$n.jpg; done
Dies setzt voraus, dass Ihre Dateinamen keine Leerzeichen oder andere merkwürdige Zeichen enthalten. Ich bin mir nicht sicher über Ihren "idealen" Fall. Wenn Sie Ihre Frage aktualisieren, um Ihre "ideale" Ausgabe anzuzeigen, sollte ich in der Lage sein, etwas für Sie herauszufinden.
Aktualisieren:
Ich habe ein kleines Perl-Skript geschrieben, das tun soll, was Sie brauchen:
#!/usr/bin/env perl my %k; ## declare the hash that will store the image names while(<>){ ## loop through STDIN chomp; ## remove newline (\n) @a=split(/_/); ## split the line on '_' and save as array @a ################################################### # Since the image names can have varying numbers # # of "_", we want to use the penultimate item in # # the array ($a[$#a-1]) as the image name prefix # ################################################### $a[$#a-1]=~s/\d*//g; ############################################################# # Now that we have the prefix ('A' or 'B' in your example), # # we will save this image name in the hash of that prefix # ############################################################# $k{$a[$#a-1]}{$_}=1; } ## The keys of the hash '%k' are all the prefixes we have found foreach my $prefix (keys(%k)){ @images=keys(%{$k{$prefix}}); ## all the images with this prefix ## Print the montage command to be executed (testing) print "montage @images -title $prefix -tile 4x $prefix.jpg\n"; ############################################################## # If the commands printed above are correct, uncomment this # # line to execute them instead of only printing. # ############################################################## #`montage @images -title $prefix -tile 4x $prefix.jpg` }
Sie können es entweder als foo.pl
oder was auch immer Sie möchten speichern und so ausführen:
ls *jpg | perl foo.pl
Oder Sie können es als One Liner betreiben:
ls *jpg | perl -e 'my %k; while(<>){$_}=1;} foreach my $prefix (keys(%k)){@images=keys(%{$k{$prefix}}); `montage @images -title $prefix -tile 4x $prefix.jpg`;}'
WICHTIG : Dieses Skript ist sehr einfach und funktioniert nicht, wenn Ihre Dateinamen Leerzeichen oder andere merkwürdige Zeichen enthalten. Ich gehe davon aus, dass dies kein Problem für Sie ist, es ist relativ einfach zu beheben, macht die Syntax jedoch umständlicher.