Please forgive me, I'm a shell noob. I need to rename a lot of directories, and would usually use a GUI utility for this, but my server access is via SMB over two VPN's, there are tens of thousands of files, and trying the GUI utility on a tiny subfolder was taking hours... So I'm using SSH, since it's many orders of magnitude faster.
I'm CD'ing to a directory with subfolders containing all the directories I need renamed, let's call it Direct1. The directories I need to rename, let's call RenameDirect
It looks like this:
/Direct1/[arbitrary directory]/SXS/[RenameDirect]/[arbitrary directories and files]
Each directory I need to rename (RenameDirect) is like this:
[arbitrary text][six-digit number][one or two spaces][4-digit year > 2000][arbitrary text]
I need to find the ones with TWO spaces in the "one or two spaces" position and change them all to ONE space there. The 2 spaces are all an error. There will be a few files with double spaces in the rest of the arbitrary text that need to preserved, so I can't just replace all double spaces.
Here's what I've come up with:
(IFS=$'\n'
find . -maxdepth 3 -type d -regextype sed -regex '.*/SXS/.*[0-9]\{6\} 20' | while read f; do
mv "$f" "$(dirname "$f")/$(basename "$f" | sed 's,\([0-9]\) \(2\),\1 \2,')"
done)
I'm pretty sure the "while," "mv," and "sed" are all working from testing them on sample folders. It's the regex arguments to "find" that are failing.
Any help would be appreciated,
Thanks.