i have a very similar question as for this post.
i would like to know how to rename occurances within a filename with designated substitutions. for example if the original file is called: ‘the quick brown quick brown fox.avi’ i would like to rename it to ‘the slow red slow red fox.avi’.
i tried this:
new="(quick=>'slow',brown=>'red')"
regex="quick|brown"
rename -v "s/($regex)/$new{$1}/g" *
but no love 🙁
i also tried with
regex="qr/quick|brown/"
but this just gives errors. any idea what im doing wrong?
Based on your example, I think you want multiple substitutions (not just converting “quick brown” to “slow red” but converting a list of words to a list of new words. You can separate the substitutions with a semicolon. Here’s a solution that works for your example:
And if you’re really bent on using an array to map the old strings to the new string, you can cram even more Perl into the argument to rename (but at some point you might just write the Perl script as a stand-alone script):