0

I'm trying to bulk rename files in bash on MacOS.

PREFIX - Full Title 1 012346.txt

I'm trying to rename them to be:

012346 - PREFIX - Full Title 1.txt

How can I do this in the shell using mv only?

AdminBee
  • 22,803
prembo
  • 101

1 Answers1

0

I used the following script:

for f in *.txt ; do
    if [[ "$f" =~  ^(PREFIX)\ -\ (.*)\ ([0-9]{6})\.txt$ ]]; then
        mv -v "${f}" "${BASH_REMATCH[3]}\ -\ ${BASH_REMATCH[1]} - ${BASH_REMATCH[2]}.txt"
    fi
done

It was based on the following answers:

prembo
  • 101