0

I have a large collection of files with filenames similar to:

myvideo.s01e01.episode.title.here.mp4
myvideo.s01e02.episode.title.here.mp4

I'd like to bulk rename them so I end up with:

myvideo.s01e01.mp4
myvideo.s01e02.mp4
etc.

I'm using macOS, but the files are on a network share, so they can also be addressed via linux.

0

2 Answers 2

2

With zsh:

autoload zmv
zmv -n '(*.s<->e<->).*(.mp4)' '$1$2'

Remove -n (dry-run) when happy.

2

If you have access to perl-rename (called rename in some Linux distros, prename in others and perl-rename in yet others), you can do:

$ rename -n 's/(.+?\..+?\.).*\.(.*)/$1$2/s' *mp4
myvideo.s01e01.episode.title.here.mp4 -> myvideo.s01e01.mp4
myvideo.s01e02.episode.title.here.mp4 -> myvideo.s01e02.mp4

That will just print what the command would do without actually renaming anything. If the output is what you would expect, then run the command without the -n to actually rename the files.

If you don't have perl-rename and the file names don't contain newline characters and have all their bytes making up valid characters in the user's locale, you can also do it directly in the shell (here assuming a zsh-like shell and a BSD-compatible sed implementation):

for f in *mp4; do 
    newName=$(sed -E 's/(([^.]*\.){2}).*\.([^.]*)$/\1\3/' <<<"$f"); 
    echo mv -- "$f" "$newName"; 
done

If that looks right, run again without the echo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .