MMV mass file rename

TL;DR

rename -n 's/^((\w+\.+){3})(.).*\.(.*)\.(.).*\.(.*)\.\-(\..*)$/$1$3$4$5$6$7/' *
  • \w+ matches one or more word characters, i.e. [a-zA-Z0-9_]+ [1]
  • \.+ matches one or more dot(.) character [2]

    Note that \. matches the . character. We need to use \. to represent . as . has special meaning in regex. The \ is known as the escape code, which restore the original literal meaning of the following character.

  • (\w+\.+){3} matches maximum 3 times of any accuracies of above [1],[2] group of characters starting from beginning(^ matches the beginning of names) of the files name.
    This will match or return my.program.name.

    Note that extra parentheses around the regex is used for grouping of matching. Grouping match starts with ( and ends with ) and used to provide the so called back-references. A back-reference contains the matched sub-string stored in special variables $1, $2,, $9, where $1 contains the substring matched the first pair of parentheses, and so on.

  • . The metacharacter dot (.) matches any single character. For example ... matches any 3 characters. so with this (.) we are matching the first character of season which it is s.

  • .*\. matches everything after a single char in above until first . if seen. As you can see we didn't capture it as group of matches because we want to remove that from our name, where this matches eason..

  • (.*) matches everything after above match. This matches NN. Parentheses used here because we want to keep that in file name.

  • \. matches a single dot after above match. A . after first NN.

  • (.) again with this one we are matching the first single character after above match. this will return only e.

  • .*\. will match everything after above match until first .. Will match pisode..

  • (.*) matches anything after last matched dot from above match. This will match second NN.

  • \.\- matches a dot. followed by a dash-. Will match or return .-

  • And finally (\..*)$ matches a single dot. and everything after that which ends to end of the file name. $ matches the end of the file name or input string.

Note: remove -n option to perform actual renaming.

Tags:

Rename

Mmv