3

I have several folders full of files with the following format:

Show Name - 07x09 - Episode Title.mp4

What I'm trying to do is rename them to the following format:

Show.Name.S07E09.Episode.Title.mp4

I've already accomplished this using a few rename commands:

rename 's/ - /./g' *
rename 's/ /./g' *
rename 's/.([0-9]+)x([0-9])/.S$1E$2/g' *

But I know there must be a better, more efficient way. How would you tackle this?

1
  • 1
    No, the idea was to remove the spaces and hyphens and have only periods as separators, then change the format of Season Number x Episode Number to SXXEXX. The actual words that make up the show name and episode titles aren't important and don't need to be treated in any special way.
    – user510807
    Jan 19 at 16:16

1 Answer 1

4

Something like this should work:

rename -n -v 's/[- ]+/./g; s/([0-9]+)x([0-9]+)/S$1E$2/' ./*.mp4

if its result was what you wanted, remove the -n option to rename your files.


Demo:

rename(./Sh  ow Name -  07x09 - Episode Title.mp4, ./Sh.ow.Name.S07E09.Episode.Title.mp4)
rename(./Sh  ow Name - 07x09 - Episode Title.mp4, ./Sh.ow.Name.S07E09.Episode.Title.mp4)
rename(./Sh  ow Name-  07x09 - Episode Title.mp4, ./Sh.ow.Name.S07E09.Episode.Title.mp4)
rename(./Sh  ow Name- -  07x09 - Episode Title.mp4, ./Sh.ow.Name.S07E09.Episode.Title.mp4)
rename(./Sh  ow Name- \---  07x09 - Episode Title.mp4, ./Sh.ow.Name.\.S07E09.Episode.Title.mp4)
rename(./Sh  ow Name--  07x09 - Episode Title.mp4, ./Sh.ow.Name.S07E09.Episode.Title.mp4)
rename(./Show Name - 07x09 - Episode Title.mp4, ./Show.Name.S07E09.Episode.Title.mp4)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.