Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to bulk change some files in bash that have spaces and unwanted endings to their extension.

For example from

abc.pdf.!ut.!ut

to

abc.pdf

I will show whole progress in case I made something harder than it should actually be. So at first I started with something like

for file in `find /Users/philippeharewood/Desktop/Film\ Sheet\ Music\ Scores\ 2  *.\!ut.\!ut`;
do
 mv $file `echo $file | sed 's/\(.*\)\.\!\ut\.\!\ut/\1/'`;
done

The above did not work for spaces when sending for mv so I changed to this

find /Users/philippeharewood/Desktop/Film\ Sheet\ Music\ Scores\ 2  *.\!ut.\!ut | while read file
do 
    mv $file `echo $file | sed 's/\(.*\)\.\!\ut\.\!\ut/\1/'`;
done

This worked almost but mv started saying an arbitrary message

usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory

I am over thinking something ?

share|improve this question
    
Execute the script with sh -xv sciptfile, it will show you the commands being executed. –  João Pinto Dec 25 '10 at 18:01
add comment

1 Answer 1

up vote 2 down vote accepted

So if you just want to remove the ending !ut.!ut I would suggest something like this:

for file in `find ...`; do
  mv "$file" "${file%.\!ut.\!ut}"
done

In this case the shell does its job and removes the ending. This feature is called parameter expansion.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.