Quote:
Originally Posted by shekhar_v4
Hi,
I have a directory with files names like ABC20090101AXY.txt, ABC20090102BZ.txt,ABC20090101COF.txt etc. The digits in the filenames represent the date. I want to rename the files to AXY.txt, BZ.txt and COF.txt
I tried with this code.
myfile= date '+ABC%Y%m%d'
for i in *.txt
do
mv $i `echo $i | sed 's/$myfile//'`
done
But its giving message
mv: ABC20090101AXY.txt and ABC20090101AXY.txt are identical
Can u help me finding the problem.
Regards,
Shekhar
|
if you have Python and can use it, here's a
ready script you can use. Usage examples
Code:
# ls -1
ABC20090101AXY.txt
ABC20090101COF.txt
ABC20090102BZ.txt
# filerenamer.py -p "ABC\d+" -e "" -l "ABC*.txt"
==>>>> [ /home/ABC20090101COF.txt ]==>[ /home/COF.txt ]
==>>>> [ /home/ABC20090101AXY.txt ]==>[ /home/AXY.txt ]
==>>>> [ /home/ABC20090102BZ.txt ]==>[ /home/BZ.txt ]