944,050 Members | Top Members by Rank

Ad:
Mar 6th, 2007
0

File ext rename

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xgringo is offline Offline
3 posts
since Aug 2006
Mar 6th, 2007
0

Re: File ext rename

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xgringo is offline Offline
3 posts
since Aug 2006
Mar 6th, 2007
0

Re: File ext rename

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!
Reputation Points: 62
Solved Threads: 10
Junior Poster
jim mcnamara is offline Offline
179 posts
since May 2004
Mar 7th, 2007
0

Re: File ext rename

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xgringo is offline Offline
3 posts
since Aug 2006
Mar 7th, 2007
0

Re: File ext rename

Change mv $file "$file".das to mv $file ${tmp}.das. It was just a typo.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Will Pay $20 Paypal: Script Help ASAP
Next Thread in Shell Scripting Forum Timeline: Need a shell script for rsync





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC