Hi, I have a script for replacing bad characters in filenames
for f in *; do mv $f `echo $f | tr '+' '_'`
done;
this replaces + for _
But I need to replace all bad characters ? / % + to _
Pls how can i do this in one script ?
Hi, I have a script for replacing bad characters in filenames
for f in *; do mv $f `echo $f | tr '+' '_'`
done;
this replaces + for _
But I need to replace all bad characters ? / % + to _
Pls how can i do this in one script ?
Perhaps the following
for file in *
do
mv "$file" $(echo $file | sed -e "s/[+%]/_/g")
done
Or within your tr you could mention
tr '+%?' '___'. Not tested though.
thx, the first script works
tr '+%?' '___'. doesnt work
With zsh:
% echo $ZSH_VERSION
4.3.4
% ls
a?b a%c a+d
% autoload -U zmv
% zmv '*' '${f//[?%+]/_}'
% ls
a_b a_c a_d
You cannot have '/' in the filename ...
Otherwise with bash/ksh93:
for f in *;do mv -- "$f" "${f//[?%+]/_}";done