Skip to content

Instantly share code, notes, and snippets.

@scrathe
Created March 23, 2020 03:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scrathe/0bedf625916df1a0d070c053c284017d to your computer and use it in GitHub Desktop.
#!/bin/sh
# what is this? identify movies that are named (movie title), THE (year) and rename to (THE movie title) (year)
OLDIFS="$IFS"
IFS=$'\n'
targetDirectories=$(find . -maxdepth 1 -type d -regextype "posix-extended" -regex '.*\,\s(The|the)\s.*' -print | cut -d/ -f 2)
for dir in $targetDirectories; do
regexThe="(.*)\,\s(The|the)\s(\(.*\))"
if [[ $dir =~ $regexThe ]]; then
movieTitle=${BASH_REMATCH[1]}
movieThe=${BASH_REMATCH[2]}
movieYear=${BASH_REMATCH[3]}
# echo "mv $dir -> $movieThe $movieTitle $movieYear"
mv "$dir" "$movieThe $movieTitle $movieYear"
fi
done
IFS="$OLDIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment