sed script to remove nth characters from end of filename

Hi all,

I have this basic script to remove, in this case 9 characters from the end of a file name. This is what I have so far,

for file in *.mov
do
newname=`echo $file | sed 's/\(.*\)........./\1/' `
mv "$file" "$newname"
done

The problem is that it removes the file extension as well.

Input:

nameofmoveotherinfo.mov

Actual Output:

nameofmovieoth

Required Output:

nameofmovie.mov

Is there a way that the script leaves the file extension but deletes the nine characters before it? Also note that the name of the movie will always be different lengths but the other info (that needs to be deleted) will always be the same length (in this case nine characters).

Any help would be appreciated.

Thanks :o

Modify your code a bit...


newname=`echo $file | sed 's/\(.*\).........\.mov/\1\.mov/' `

Thanks Rakeshawasthi! Worked perfectly :slight_smile: