954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

File ext rename

PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

I have AIX so I can't use rename hopeing for something easier but I need to find all the files in the directory and then any of them that have a .err on them I need to be able to rename them back all the way to the .das

So I need to go from

PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

to

PQPZ3.DATR.QRL.R9529.D090295.T19501.das

When I have many .err's one quick script to rename them all back to the .das

xgringo
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

I tried something like this but it just adds a .das at the end of the whole file...

for i in *.das; do mv "$i" `basename $i`.das; done

xgringo
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

You have to use either ksh (zsh) or bash to do this - ie., a modern shell with pattern matching.

cd /path/to/files
find . -name '*.err' |\
while read file
do
	tmp=${file%%.das*}
	mv $file "$file".das
done


Test it somewhere first!

jim mcnamara
Junior Poster
180 posts since May 2004
Reputation Points: 62
Solved Threads: 10
 

This just added the .das at the end of the .err I need something to remove it all the way back tot he .das

PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

to

PQPZ3.DATR.QRL.R9529.D090295.T19501.das

xgringo
Newbie Poster
3 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

Change mv $file "$file".das to mv $file ${tmp}.das . It was just a typo.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You