查找文件名中最大的数值

问题描述 投票:0回答:1

我已经研究了三天了,所以我在这里提出我的问题。我有一个剧本,用来标准化我的电视剧。最后,一切看起来都像这样的语法:

([\w\d\s]+)(_S(\d{2})E)(\d{1,3})
这是一个例子: 一切从这里开始_S01E51.mkv

我想找到并重命名本季最后一集。 例子: 一切从这里开始_S01E51 - Final.mkv

有人可以帮我找到解决方案吗? 非常感谢!

bash scripting find
1个回答
0
投票

循环文件,使用参数扩展提取剧集编号。将最大值存储在变量中。

#!/bin/bash
max=0
for f in 'Here it all begins_S01E'*.mkv ; do
    n=${f##*E}   # Remove everything up to the last E.
    n=${n%.mkv}  # Remove the extension.
    if (( n > max )) ; then
        max=$n
    fi
done
echo 'Here it all begins_S01E'$max.mkv
© www.soinside.com 2019 - 2024. All rights reserved.