Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr:bin/perl
- use strict;
- use warnings;
- my $target = $ARGV[0];
- my $delim = '_';
- my @filenames = `ls $target`;
- my %common_words;
- my $first=1;
- for my $filename (@filenames)
- {
- chomp($filename); # remove trailing newline if any
- #$filename =~s/\.[^.]+$//; # remove extention, beware with doubles like ".tar.gz"
- my @words = split($delim, $filename);
- print "words : @words\n";
- if( $first )
- {
- print "first name : $filename\n";
- foreach (@words)
- {
- $common_words{$_} = 1;
- }
- $first = 0;
- }
- else
- {
- print "non-first name : $filename\n";
- foreach my $word (keys %common_words)
- {
- if (not grep(/$word/,@words))
- {
- delete $common_words{$word};
- }
- }
- }
- }
- foreach my $filename (@filenames)
- {
- foreach my $word (keys %common_words)
- {
- my $filename_new = $filename;
- $filename_new =~ s/$word$delim//g;
- $filename_new =~ s/$delim$word//g;
- system "mv $target$filename $target$filename_new";
- $filename = $filename_new;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement