Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename multiple file 2

Status
Not open for further replies.

mrimagepueblo

Programmer
Dec 15, 2003
52
US
I have tried figuring out some of the similar posts but can't seem to match up the examples with what I need.

I want to create a shell script that will automatically rename a bunch of graphics files cutting off the last part of the filename as their is no pattern to match on without a bunch of if statements.
The filenames for example are
5568012_101_12.jpg
5652901_101_12.jpg
5890390_101_13.jpg
5992313_101_71.jpg

I simply want the files to be renamed as
5568012.jpg
5652901.jpg
5890390.jpg
5992313.jpg

thanks a bunch in advance
 
One way:
ls *_*.jpg | awk '{split($0,a,"_");print "mv "$0" "a[1]".jpg"}' | sh -v

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This worked great! I had additional files like 5652901_201_12.jpg and it stripped the _201_ files as well. Excellent answer and in less than 15 minutes to solve this. Now I will try and figure out what exactly it's doing.
 
I'm glad you got your problem sorted... with a very nifty solution i must say!


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top