Help pls...Rename .dat files

Hi,

I have some .dat files in some directories , i want them to be moved to another directory by changing file names.

for ex:

cat > /ai/rcmid/feb_files/temp/temp.txt
aaa.dat
bbb.dat
rm -rf main
rm -rf a001
rm -rf a002
mkdir main
mkdir a001
mkdir a002
touch a001/aaa.dat
touch a001/bbb.dat
touch a002/aaa.dat
touch a002/bbb.dat
while read fname1
do

c=1
while [[ $c -le 2 ]]
do
  mv /ai/rcmid/feb_files/temp/a00"$c"  /ai/rcmid/feb_files/temp/main/"${fname1}_${c}"
   	
let c=c+1
done

done </ai/rcmid/feb_files/temp/temp.txt

Here i am unable to change the .dat names, the above code is creating multiple directories which is not expected. can you please help.

---------- Post updated at 03:56 PM ---------- Previous update was at 03:47 PM ----------

I need O/P as below:

cd main
ls
aaa_001.dat
aaa_002.dat
bbb_001.dat
bbb_002.dat

---------- Post updated at 05:05 PM ---------- Previous update was at 03:56 PM ----------

Pls Can any one please check and respond

You did not cd, so where is this always running?

First outer loop reads aaa.dat and first inner loop has c=1, so if there is a /ai/rcmid/feb_files/temp/a001 then it moves to /ai/rcmid/feb_files/temp/main/aaa.dat_1 which is not your desired first file or dir.