LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   changing extension of multiple files (https://www.linuxquestions.org/questions/linux-general-1/changing-extension-of-multiple-files-140023/)

shaggystyle 01-29-2004 11:53 AM

changing extension of multiple files
 
I have a directory with a ton of images in it and I'm trying to rename all of the files to have a specific extension (.thumb.jpg for thumbnails) here is what I have so far:

for file in *.jpg; do echo $file; mv $file $file.thumb.jpg; done

EX: test.jpg -> test.thumb.jpg

only problem is, the second argument to the mv includes the previous extension. I.E. test.jpg -> test.jpg.thumb.jpg

Is there a wildcard that would drop the extension? ($file includes extension and I don't want that).

I hope this isn't too confusing. I'm not entirely sure what I"m asking myself but I'm trying to make it as clear as possible.

homey 01-29-2004 11:58 AM

Just trying to get things clear....

You have files with the .jpg extension.
What do you want them to look like?

shaggystyle 01-29-2004 11:59 AM

*.thumb.jpg

druuna 01-29-2004 12:04 PM

Is this what you want:

for file in *.jpg; do echo $file; echo ${file%%jpg} ; done
blaat.jpg
blaat.

shaggystyle 01-29-2004 12:09 PM

yes, thats exactly what i needed....thanks a ton.

you just save me hours of renaming and a lot of carpel tunnel pain!

homey 01-29-2004 12:35 PM

Rats, beat me to it! :) And here are a couple of other ways to do it.....

for i in *.jpg; do j=`echo $i | awk -F. '{print$1".thumb."$2}'`; mv "$i" "$j"; done

or if using sed......

for i in *.jpg; do j=`echo $i | sed -e "s/".jpg"$/".thumb.jpg"/g"`; mv "$i" "$j"; done


All times are GMT -5. The time now is 09:27 AM.