UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and
I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server

$ cat temp.txt
RTG*888*TD8*20180201~
TWW*888*RD8*20180201-20180201~
RTG*888*TD8*20180201-20180201~
KCG*888*TD8*20180201-20180201~

I want the output as below by changing date. Please help. I am looking for UNIX script to make it work for all files present in that directory

RTG*888*TD8*20190417~
TWW*888*RD8*20180201-20180201~
RTG*888*TD8*20190417-20190417~
KCG*888*TD8*20180201-20180201~

Thanks in advance

for file in *; do
   # check if it's a file
   if [ ! -f "$file" ]; then
        # if not, next entry
        continue;
   fi

   # run the script
   while IFS='*' read -r str1 num str2 date; do
        if ["$str1" = "DTP"] || ["$str2" = "D8"]; then
            curdate=$(date +%Y%m%d)
            date="${curdate}-${curdate}~"
        fi
        printf "%s*%s*%s*%s\n" "$str1" "$num" "$str2" "$date"
    done < "$file"

done

What shell are you using?

What version of that shell are you using?

What diagnostic messages are printed when you try running your script?

If you are looking for "$str1" = "RTG" AND "$str2" = "TD8" , why is your code looking for "$str1" = "DTP" OR "$str2" = "D8" ? And, on that if statement do you think some of the diagnostics you are seeing might be because you didn't separate the arguments with spaces?

There seem to be two different date output formats you want to produce, but your code doesn't seem to make any attempt to distinguish between the two. Is the output that you want incorrectly displayed, or have you just not bothered to try to figure out which output format should be produced when looking at the input line?

You say you want a date 15 days ago, but there is nothing in your code that attempts to print anything but today's date. There are lots of threads here that deal with date calculations. Have you searched through them to find a method that meets your needs? (Again, we need to know what shell and what version of that shell you are using!)