How to remove escaped characters in file names?

I would like to remove escaped characters from file names, so these examples

=Web_Help_Desk_Pro%26Lite.pdf =Windows_7_%2b_s-drev.pdf 

will become

 =Web_Help_Desk_ProLite.pdf =Windows_7__s-drev.pdf 

Does anyone know how to do this in Perl or BASH?

+4
source share
6 answers

To simply remove the percent sign and the following two hexadecimal digits:

 $path =~ s/%[\da-f][\da-f]//gi; 
+2
source

If $file is your file name:

 my $file = '=Web_Help_Desk_Pro%26Lite.pdf'; $file =~ s/%[0-9a-f]{2}//gi; 

i.e. replace % followed by two hexadecimal characters with an empty string.

+3
source

This should work

 sed 's/%[[:alnum:]]\{2\}//g' INPUT_FILE 
+2
source

Based on 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 
+2
source

If you don't mind addiction, there is a convmv 'command:

 convmv --unescape --notest <files> 
0
source

Try the following:

 rename 's/\r//' *.html 
0
source

Source: https://habr.com/ru/post/1390129/


All Articles