renaming files with numbers

I have files of the sort

dhfmovie1.txt
dfhmovie2.txt

and want to rename them to

dhfmovie01.txt
dhfmovie02.txt

the files are in a directory with many other files, I only need to do this for files with 1-9 in the name. can anyone help me with the correct sed/mv script?

thanks

ls -1 dhfmovie* | sed -n 's/\(dhfmovie\)\([0-9]\)\(.txt\)/mv & \10\2\3/p' | sh

Hi,

I am not very sure about your requirements, seems you did not specific it.

Suppose you have a file:
a1b3.txt
what should be the result? a01b03.txt or a1b03.txt?

Anyway, follow may help you some or so.

code:

echo 'Input directory'
read dir
for i in `ls -l $dir | nawk '$9 ~ /[0-9]/ {print $9}'`
do
new=`echo $i | sed 's/[0-9]/0&/g'`
mv $i $new
done

result:

a.txt --> a01.txt
a1bc --> a01bc