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!

Renaming files 1

Status
Not open for further replies.

jckrell2

Programmer
Nov 4, 2003
13
US
Hello,

Can anyone help me in renaming about 1000 files I have.

The file names are like 21-10-03-902-02.tif
The change i need to make is in the third set of digits (where the 03 is in this example). I need to make the 2 digits to be 3 digits with a leading 0.
In the above example 21-10-03-902-02.tif would need to become 21-10-003-902-02.tif
25-25-25-100-10.tif would need to
become 25-25-025-100-10.tif. I simply need to make the two digits to be 3 digits with a leading 0.

I don't know much about shell scripting and need to get this done. Any help would be greatly appreciated.

Johnny
 
If they're always this same format for the name, this might do it...
Code:
#!/bin/ksh

for FNAME in *-*-[0-9][0-9]-*.tif
do
    mv ${FNAME} $(echo ${FNAME}|sed 's/-/-0/2')
done
This takes every file that has two numeric digits after two dashes, and just adds a "[tt]0[/tt]" after the second dash.

Maybe add a [tt]print[/tt] or [tt]echo[/tt] in there to see what it's doing, but that should do it.

Hope this helps.

 
YES!!

This absolutely did exactly what I needed.
Thanks a million SamBones. You saved my day!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top