UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old September 22nd, 2004, 09:39 PM
jun_moti jun_moti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 7 jun_moti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi... Hope u cud help me.... how can i rename the extension file by batch?....

Hi... Hope u cud help me.... how can i rename the extension file by batch?....

ex. abc.dat
cde.dat
efg.dat
to
abc.dml
cde.dml
efg.dml

thank you!..

-jun

Reply With Quote
  #2  
Old September 23rd, 2004, 01:07 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
the probl is that extra ex., you can do it in a 3 steps sed:
Code:
#!/bin/sh
OLD=dat
TMP=+++
NEW=.dml
for old in *.$OLD
do
new=`echo $old|sed "s/\.$OLD/$TMP/;s/^.*\.//;s/$TMP/$NEW/"`
echo mv $old $new
done

delete 'echo' before 'mv' to make it sharp

Reply With Quote
  #3  
Old September 23rd, 2004, 01:47 AM
hchou hchou is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 7 hchou User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Got a quick question...

What happen if you have file with name like temp.dat.dat?

This script will fail....

Reply With Quote
  #4  
Old September 23rd, 2004, 02:01 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
not really, yes i forgot the $
try:
new=`echo $old|sed "s/\.$OLD$/$TMP/;s/^.*\.//;s/$TMP/$NEW/"`

tmp.dat.dat becomes dat.dml
OK: tmp.dat.dat.dat.dat will also become dat.dml
if rules are not clear, do it by hand, no other choice.

sure to do it the right way, you should check the new
file name .....
so i would use an other tool, c || perl will be better!

the Q here is: isole .dat at end of string, then purge
.*\. at begin, finally replace the replaced .dat

ex. abc.dat # here you get troubles
cde.dat # no probls here: s/dat$/xxx/

the 2.nd Q is: the generic code

Last edited by guggach : September 23rd, 2004 at 02:37 AM. Reason: typo

Reply With Quote
  #5  
Old September 23rd, 2004, 12:06 PM
hchou hchou is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 7 hchou User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Hi... Hope u cud help me.... how can i rename the extension file by batch?....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway