I currently have a script where I rename files by removing whitespace and certain names. This is about 200 names so far so I though an array of names I want to exclude would be a better option.
prename -v 's/ /_/g' *
prename -v 's/_-_/_/g' *
prename -v 's/_\(Summer-HD\)//ig' *
prename -v 's/_\(Hammer\)//ig' *
prename -v 's/_\(Hardware-Hybrid\)//g' *
prename -v 's/_\(digital\)//ig' *
prename -v 's/_\(Resolution-SD\)//ig' *
This is what i have tried so far, a for loop to iterate over the names I want to exclude and but that has not worked.
exclude=('(Summer-HD)' '(Hammer)' '(digital)' '(Resolution-SD)' '(Vacation)' '(Hammer-Hybrid)')
for x in "${exclude[@]}";
do prename -v 's/$x/_/g' * {} \;
done
This for loop does not work at all and just leaves me with a blinking cursor. I'm not sure if I can pass a variable to prename. I modified the for loop a bit on some advise about wrapping things in double quotes.
for x in "${exclude[@]}";
do prename -v 's/$x/_/g' *"$x"* {} \;
done
This also does not work, and now I have no idea what all is going on here. I still want to have the array for the names since I currently have more than 200 that i would like to remove. As for prename, I'm not married to the idea, I have heard sed could help or awk. Neither I am comfortable with to do this in. Thanks for any ideas or help provided.
for
loops withfind
syntax.{} \;
is used withfind
's-exec
and-execdir
to pass filename args to the program being executed.