Removing characters of a list of filenames.

in sh alike shells, some examples:
Code:
for i in list of files; do mv -f  $i $(echo $i | tr " \(\)\[\]\{\}/_/g" "_"); done

or
Code:
for i in `ls /path/to/files/`; do mv -f $i $(echo $i | tr " \(\)\[\]\{\}/_/g" "_"); done

Code:
for i in `ls /path/to/files/`; do mv -f $i $(echo $i | sed 's/ā/_/g') | sed 's/š/_/g' | sed '/ē/_/g'; done
Last one I haven't tested... it uses utf-8 2 byte characters... but i think it should work

here's my rmwinshit.sh
 
Based on your feedback I tried something different:

Code:
for i in `ls`;
do newname=`echo $i | sed 's/string_to_replace/new_string/g'`;
mv $i $newname;
done

This seems to work too, considering we're in the right directory with only files.
 
Fixed bugs....
sed really wan't good choice... tr is much better for you.... also sed wouldn't work the way I wrote at first.... {I was thinking of using it as tr.... )

please check my 1st post again
 
Here is another one I found that works pretty well. It replaces empty space in a file mane with a character. In this example empty space in the file name is replaced by "-":

Code:
find . -name "* *"| while read file
do
  rename "$file" "`echo "$file"| nawk ' BEGIN {OFS="-"} $1=$1 '`"
done
 
Back
Top