I have gone through various solution for renaming but none of them found fit in this situation. I have to rename a file oldfilename to newfilename with conditions like
Prefix the hard coded string like
followed by appending a part of old file name till any special character, if any
followed by appending date that was calculated before like
date = $(date +"%a, %d %b %Y %T %z)
adding a custom extension like
followed by triming any space inbetween files created above that I did like
newFileName = "Pre_String_$oldfilename_$date.abc" | tr -d ' '
Finally i echo string
echo "filename is $newFileName"
and then rename the oldfilename to newFilename
mv -v "$path$oldfilename" "$path$newFileName"
but even the simple one like above is not working. I did many changes but either it is taken as command not found or halflway string or mostly empty in echo. Also strangly enough the 7 command in most of hit and try gave the newFilename as exactly the oldfilename.