Copying and renaming files

hi,

 
source directory as /home/home01
target directort as /home/home02

I have below files in source directory:

 
FrontOf_history.dat
FrontOf_history1.dat

In target directory have many files as:

 
Kront_2014.dat
Kront_2015.dat
Kront_2016.dat

Now i want to copy the two files present in source_dir to target_dir
after copying the two files i want to rename these two files as:

 
FrontOf_history_$date.dat
FrontOf_history1_$date.dat

where $date is a input parameter string

I have written below script for that:

 
date=`awk 'NR>5; END{print}' /home/home03/date.dat`
source_dir="/home/home01"
target_dir="/home/home02"
cd $source_dir
ls FrontOf_*.dat >>/tmp/abc.dat
file1=`grep "FrontOf*" /tmp/abc.dat
cp ${source_dir}/${file1} ${target_dir}
ls ${target_dir} | while read file1
do
        pre=`echo ${file1} | cut -d"_" -f1`
        post=`echo ${file1} | cut -d"_" -f3-4`
        new_name1="${pre}_${date}_${post}"
        mv $target_dir/$file1 $target_dir/$new_name1
done

Problem with this code is that it is renaming other files also that in present in target_dir.I just want to rename the two files that I copied from source to target directory.

If I understand your problem statement correctly, this should do what you want.

date=`awk 'NR>5; END{print}' /home/home03/date.dat`
source_dir="/home/home01"
target_dir="/home/home02"

## Here the core logic.
for i in `ls ${source_dir}/FrontOf_history*.dat`;do
  fname=`basename $i|sed "s/\(.*\)\.*/\1"`
  cp $i ${target_dir}/${fname}_${date}.dat
done