I have a lot of files I want to rename and it would take me a long time to do them manually. They are video files and are usually in this format - "NAME OF SHOW - EPISODE NUMBER - EPISODE NAME", so for example "Breaking Bad - 101 - Pilot".
What I would like to do is change the "101" part to my own convention of "S01E01". I figure that in one series of a show the only sequential part of that string is the last number, ie. S01E01, S01E02, S01E03, S01E04 etc...
Would anyone be able to give me advice on how to do this on terminal on Mac OS X. I believe it is too complicated to do with Automator or other batch renaming programs...
Thanks
The following script will find all .mp4 with one string of 3 consecutive numbers. Example something.111.mp4 . It will convert it to something.S01E11.mp4 . It will also exclude any sample files.
Like the previous script it will only work if less than 10 seasons.
For those that are trying to personalize for their current directory tree, I would recommend learning the sed and find command. They are pretty powerful, are simple, and will allow you to substitute any string within a file name.
The following solution:
107
for season 1, episode 7, or1002
for season 10, episode 2)find
andbash
techniques, such as:-regex
primary to match filenames by regular expression (rather than wildcard pattern, as with-name
)execdir
to execute a command in the same directory as each matching file (where{}
contains the matching file name only)bash
script that demonstrates regular-expression matching with=~
and capture groups reported via the built-in${BASH_REMATCH[@]}
variable; command substitution ($(...)
) to left-pad a value with zeros; variable expansion to extract substrings (${var:n[:m]}
).This works if there are less than 10 seasons.
Using the
perl
rename
implementation which easily can take care of proper padding and works for any number of seaons and episodes (<100, but can easily be adapted to your current format):I think
homebrew
ships with the correct version, so it's just a matter of installing via