Reputation: 25996
I would like to remove escaped characters from filenames, so these examples
=Web_Help_Desk_Pro%26Lite.pdf
=Windows_7_%2b_s-drev.pdf
would become
=Web_Help_Desk_ProLite.pdf
=Windows_7__s-drev.pdf
Does anyone know how to do this in either Perl or BASH?
Upvotes: 4
Views: 1024
Reputation: 6615
If you don't mind the dependency, there is a command 'convmv':
convmv --unescape --notest <files>
Upvotes: 0
Reputation: 25996
Based on all your help, I came up with
for f in $(find . -name \*.html); do
mv $f $(echo $f | sed 's/%[a-z0-9][a-z0-9]//gi')
done
Upvotes: 2
Reputation: 52039
To just remove the percent sign and the following two hex digits:
$path =~ s/%[\da-f][\da-f]//gi;
Upvotes: 2
Reputation: 339816
If $file
is your filename:
my $file = '=Web_Help_Desk_Pro%26Lite.pdf';
$file =~ s/%[0-9a-f]{2}//gi;
i.e. replace %
followed by two hex characters with the empty string.
Upvotes: 3