Sandra Schlichting
Sandra Schlichting

Reputation: 25996

How to remove escaped characters in filenames?

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

Answers (6)

fabriberloco
fabriberloco

Reputation: 9

Try this:

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

Upvotes: 0

David C. Bishop
David C. Bishop

Reputation: 6615

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

convmv --unescape --notest <files>

Upvotes: 0

Sandra Schlichting
Sandra Schlichting

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

jaypal singh
jaypal singh

Reputation: 77105

This should work

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

Upvotes: 2

ErikR
ErikR

Reputation: 52039

To just remove the percent sign and the following two hex digits:

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

Upvotes: 2

Alnitak
Alnitak

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

Related Questions