0

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!

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
cjramone
  • 1
  • 1
  • 1
    You might have an encoding problem. Make sure that the file and your terminal environment are both using UTF-8. (e.g. `export LC_ALL=it_IT.UTF-8` for the shell, and `:set filenecoding=utf8` in vim). – Mark Reed Dec 12 '14 at 13:15
  • Related and useful: [How to remove all of the diacritics from a file?](http://stackoverflow.com/questions/10207354/how-to-remove-all-of-the-diacritics-from-a-file) – fedorqui Dec 12 '14 at 13:17

3 Answers3

2

Change your sed like below,

echo $FILE | sed "s/à/a'/g"
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0
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

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
0

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);
}
Mark Reed
  • 91,912
  • 16
  • 138
  • 175