I am having a problem writing a script for mass renaming of files in subdirectories.
I have a folder with multiple subfolders, and those subfolders have multiple files that I need to rename.
This is the where I got so far:
for file in $(find -name "*.report")
do
mv "$file" "LPP_${file/LP_/}"
done
So as you can see, I need to replace the 'LP_' string in the filename with the 'LPP_'.
This is not working because of the path to the file - the strings retrieved from the find command are only file names, and don't include the path. To include the path, I am trying something like this:
for file in $(find -name "*.report")
do
echo "$file"
echo "${RELPATH/\$\//}/${file/LP_/LPP_}"
done
But the RELPATH variable is prefixing a '/' character, so the mv command is complaining that it cannot move the file to /./subfolder1/LPP_filename.report
Can someone tell me what am I doing wrong, is there a better way of doing it, and explain why is there an extra '/' character in te RELPATH variable and how to remove it?
Thank you all in advance!