You could also use the perl-based rename
command: something like
rename -- 's/(\w+)\s+(\w+).*/$1_$2.mp4/' *.mp4
which takes the first two "words" (sequences of word characters, separated by whitespace), discards the remainder of the name, and then outputs the words separated by an underscore followed by the .mp4
dot extension.
If you want to title-case the first word as indicated in your question, you could do that using \u
and \L
modifiers
rename -- 's/(\w+)\s+(\w+).*/\u\L$1_$2.mp4/' *.mp4
Testing using the -n
(no-op) and -v
(verbose) switches with your sample filename
$ rename -nv -- 's/(\w+)\s+(\w+).*/\u\L$1_$2.mp4/' *.mp4
NARUTO 50 — The Fifth Gate- A Splendid Ninja is Born_low.mp4 renamed as Naruto_50.mp4
You could get fancier - for example making it handle dot suffixes more generally rather than assuming they are all .mp4
- you may find this Regex Tutorial useful.