I'm wondering if I can use this for my problem? It's a little different, but I can't seem to figure out how to do it. I'm trying to copy a changing list of files from one directory to another while adding a variable prefix and a date suffix to a file name before the file extension. The problem is the files might have multiple extensions.
For example, I have two files:
test1.zip
test2.txt.pgp
I would like to move them to the other directory while changing the name. So I would like the copied files to be:
MAP_test1_20041110.zip
MAP_test2_20041110.txt.pgp
I can change the file name fine. But can't figure out how to maintain the file extensions.
Here's what I have so far:
fname=test2.txt.pgp
comp_sym="MAP"
newfilename=$comp_sym"_"${fname%%.*}"_"`date +%Y%m%d`
(this will get me MAP_test2_20041110 but can't figure out how to get those varied file extensions)
Thanks