I have folders setup like this:
/path/to/directory/SLUG_1/SLUG_1 - SLUG_2 - SLUG_3
SLUG_2 is a year, and it may have a letter after the year, like "1994" or "2003a".
I would like to rename those files to:
/path/to/directory/SLUG_1/SLUG_2 - SLUG_3
I'm getting pretty close with this command:
find $root -mindepth 2 -maxdeth 2 -type d | sed "s#\(\(/path/to/directory/[^/]*/\).* - \([0-9]\{4\}[a-bA-B]\? - .*\)\)#mv "\1" "\2\3"#
This prints:
mv "/path/to/directory/SLUG_1/SLUG_1 - SLUG_2 - SLUG_3" "/path/to/directory/SLUG_1/SLUG_2 - SLUG_3"
Which is exactly the command I want to execute. But I can't execute it.
I tried assigning the output to a variable and executing it by calling the variable. That didn't work. I tried a few variations on that idea, and I got errors.
It feels like I'm missing some tool here. Some iterating tool that makes this job easy. Any suggestions?
|bash
won't work if there are special characters in file names such as spaces. You can make it work, but it's a lot more complicated than simplefind
usage. – Gilles 'SO- stop being evil' Oct 27 '16 at 22:41mv
command with the needed double quotes. – Wildcard Oct 27 '16 at 23:45