Rename files using regular expression in linux

后端 未结 7 1442
北恋
北恋 2020-12-04 14:03

I have a set of files named like:

Friends - 6x03 - Tow Ross\' Denial.srt
Friends - 6x20 - Tow Mac and C.H.E.E.S.E..s         


        
7条回答
  •  孤街浪徒
    2020-12-04 14:34

    You can use rnm:

    rnm -rs '/\w+\s*-\s*(\d)x(\d+).*$/S0\1E\2.srt/' *.srt
    

    Explanation:

    1. -rs : replace string of the form /search_regex/replace_part/modifier
    2. (\d) and (\d+) in (\d)x(\d+) are two captured groupes (\1 and \2 respectively).

    More examples here.

提交回复
热议问题