File ext rename

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2006
Posts: 3
Reputation: xgringo is an unknown quantity at this point 
Solved Threads: 0
xgringo xgringo is offline Offline
Newbie Poster

File ext rename

 
0
  #1
Mar 6th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: xgringo is an unknown quantity at this point 
Solved Threads: 0
xgringo xgringo is offline Offline
Newbie Poster

Re: File ext rename

 
0
  #2
Mar 6th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: File ext rename

 
0
  #3
Mar 6th, 2007
You have to use either ksh (zsh) or bash to do this - ie., a modern shell with pattern matching.
Shell Scripting Syntax (Toggle Plain Text)
  1. cd /path/to/files
  2. find . -name '*.err' |\
  3. while read file
  4. do
  5. tmp=${file%%.das*}
  6. mv $file "$file".das
  7. done

Test it somewhere first!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: xgringo is an unknown quantity at this point 
Solved Threads: 0
xgringo xgringo is offline Offline
Newbie Poster

Re: File ext rename

 
0
  #4
Mar 7th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,450
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 261
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: File ext rename

 
0
  #5
Mar 7th, 2007
Change mv $file "$file".das to mv $file ${tmp}.das. It was just a typo.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC