On 10/17/2007 12:13 AM, H.S. wrote:
[...]And here is the command that finds all my image files in directory E and renames them using the above script:$> find E/ -name "*.[Jj][Pp][Gg]" -exec ./delparen.sh "{}" \; BTW, for some reason, the following does not work: $> for f in `find E/ -name "*.[Jj][Pp][Gg]"`; do echo "$f"; done The output of the above command has a new line before each parenthesis.
Perl comes with a rename command that handles this fairly well. Here are some ways of solving your problem both with and without rename (watch out for line-wrapping):
find E.DIR/ -name "*.[Jj][Pp][Gg]" -exec rename 's/ *\((\d+)\) */$1/g' "{}" \;
find E.DIR/ -name "*.[Jj][Pp][Gg]" -print0 | xargs -n3 -0 rename 's/ *\((\d+)\) */$1/g'
find E.DIR/ -name "*.[Jj][Pp][Gg]" -print | \ while read fn do nn2=`echo "$fn" | sed -e 's/ *(\([0-9]\+\))/\1/'` mv "$fn" "$nn2" done For the solution that uses xargs, it's probably okay to remove the -n3. HTH