I have a fixed 4 files in each different directory. The total 17 directories are there each one having 4 files inside it. I need rename all of them with current date. The files formates will be as below:
#!/bin/ksh
today=$(printf "%(%d%m%Y)T" now)
echo "$today"
# fix filegeneration if needed. My example has done in main directory and
# those 17 directories are subdirectories
for f in */abc_???_???_????????.txt
do
# parse line using delimeter _ and .
echo "$f" | IFS="_." read part1 part2 part3 partdate end str
partdate="$today" # newdate value
newname="${part1}_${part2}_${part3}_${partdate}.${end}"
[ -f "$newname" ] && echo "$newname already exist" >&2 && continue
# remove echo after you have tested
echo mv "$f" "$newname"
done