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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming Files

Status
Not open for further replies.

aschneck

IS-IT--Management
Oct 31, 2002
12
DE
Hi,
doing a recursive search through a folder and it's subfolder I want to rename special files, if found there.
Example:
folder1\afile.blah
folder1\afile1.bla
folder1\folder2\afile.blah

All those should be autom. renamed in changing the leading a to b:
folder1\bfile.blah
folder1\bfile1.bla
folder1\folder2\bfile.blah

I think the first part of the script could be a 'find folder1/. -name a*.blah -type f -exec script2 {} \;' while script2 can do the rename with awk? But I'm not sure how the awk commands must be use.
Can you help?
Axel
 
This is not awk, just a shell script...

find folder1/. -name a*.blah -type f -print | while read FILENAME
do
[gray]#----use basename and dirname to extract portions of path names[/gray]
DIR=`dirname $FILENAME`
BASE=`basename $FILENAME`
[gray]#----use sed to replace leading 'a' with 'b'[/gray]
NEWNAME=`echo $BASE|sed s/^a/b/`
[gray]#----rename the file[/gray]
mv $FILENAME $DIR/$NEWNAME
done


 
Ah, great!
Thanks a lot, it's working well!
bye,
Axel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top