Issue
I'm trying to change the substring of a filename where it is contained within several sub folders. Currently I'm using rename with 'homebrew renaame' but am running into issues.
I'd like to change 'CorporateAssessments-' to 'CorporateAssessments'. Here is my current code:
for x in $(find . -name CorporateAssessments-\*); do
rename 's/CorporateAssessments-/' *CorporateAssessments*
done
When running this I get this error "Substitution replacement not terminated at (eval 2) line 1." Any suggestions?
Solution
Assuming you have rename
perl utility installed, you can use this find + rename
:
find . -name 'CorporateAssessments[ -]*' -exec \
rename 's/(CorporateAssessments)[ -]/$1/' _ {} +
If you don't have rename
utility installed then use this find + mv
:
find . -name 'CorporateAssessments[ -]*' -exec \
bash -c 'mv "$1" "${1//[ -]}"' _ {} +
Answered By - anubhava Answer Checked By - Dawn Plyler (WPSolving Volunteer)