Reputation: 1
I've got to rename a file such that: IndennitàMalattia.doc
by replacing the character à with a'
.
The following sed command works in the command line, but not inside a .sh file.
echo $FILE | sed -e s/à/a\'/g
Can someone please help me? Thanks!
Upvotes: 0
Views: 1476
Reputation: 95252
You may find this Perl script useful. It will rename specified files by turning all grave accents into apostrophes:
#!/usr/bin/env perl
use v5.14;
use autodie;
use warnings;
use warnings qw( FATAL utf8 );
use utf8;
use open qw ( :encoding(UTF-8) :std );
use charnames qw( :full :short );
use Unicode::Normalize;
# if no args specified, use example from question
@ARGV = qw(IndennitàMalattia.doc) unless @ARGV;
foreach my $old_name (@ARGV) {
(my $new_name = NFD($old_name)) =~ s/\N{COMBINING GRAVE ACCENT}/'/g;
say qq{Renaming "$old_name" to "$new_name"};
rename $old_name, NFC($new_name);
}
Upvotes: 0
Reputation: 10039
mv "${File}" "$( echo "${File}" | sed "s/à/a'/g;s/è/e'/g;s/ì/i'/g;s/ò/o'/g;s/ù/u'/g" )"
and any other accent char equivalent
Upvotes: 0