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