How to change automatically the file names

Hi all,

I need to replace automatically all special characters of one filename with some corresponding characters

For example >

� --> oe

� --> ae

....

If the special character comes more than one time, then all the coccuerences have to be replaced.

I would like to have a acript, which could do the replacement through the whole file system.

Can somebody help me please

Thanks in advance

MAKY

Try this.

#! /bin/sh

for file in `find /dir/to/search -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH}
FILE_NEW={FILE_OLD//<special-char>/<replacement>}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done

Not tested tho'.

<special-char> is the char you wish to replace.
<replacement> is the replacement.

Vino

Vino, thanks for the quick reply, but I couldn't get any result yet.
I have written your script in the following form, making the test for replacing all the z letters with d letters

#! /bin/sh

for file in `find /tmp/ -name '*.'`
do
PATH=${file%/
}
FILE_OLD=${file#$PATH}
FILE_NEW={FILE_OLD//<z>/<d>}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done

The script doesn't give any error but also doesn't replace any charecters.

Thanks in advance
MAKY

#! /bin/sh

for file in `find /tmp/ -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH}
FILE_NEW=${FILE_OLD//z/d}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done

vino

Sorry, but I still do not receive any result.
Did you try it ay your system and get the result ?
Thanks again
MAKY

#! /bin/sh

for file in `find /tmp/ -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH/}
FILE_NEW=${FILE_OLD//z/d}
mv ${file} ${PATH}/${FILE_NEW}
done

Vino

Vino, your mv command is invalid, must be :

mv ${file} ${PATH}/${FILE_NEW}

Another way to do the work

# Transcodification table
Trans_table="�=oe,�=ae"

# Build sed script to do file name transcodification
sed_file=/tmp/$$.sed

echo "$Trans_table" | tr '=,' ' \n' |
while read from to
do
   echo "s/$from/$to/g"
done  > $sed_file

# Rename all files in the system
for file in `find /`
do
   path=`dirname $file`
   file_old=`basename $file`
   file_new=`echo $file_old | sed -f $sed_file`
   [ "$file_old" != "$file_new" ] && mv $path/$file_old $path/$file_new
done

rm -f $sed_fil