|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Got a quick question...
What happen if you have file with name like temp.dat.dat? This script will fail.... |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Thanks...
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Hi... Hope u cud help me.... how can i rename the extension file by batch?.... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|