我有很多文件要重命名,手动重命名需要很长时间。它们是视频文件,通常是这样的格式-“剧集名称-剧集编号-剧集名称”,例如“绝命毒师- 101 -飞行员”。
我想做的是将"101“部分改为我自己的惯例"S01E01”。我认为在一个系列的节目中,该字符串的唯一连续部分是最后一个数字,即。S01E01、S01E02、S01E03、S01E04等
谁能给我关于如何在Mac OS X的终端上做这件事的建议。我相信这是太复杂了,用Automator或其他批处理重命名程序...
谢谢
发布于 2013-01-12 21:38:13
for FOO in *; do mv "$FOO" "`echo $FOO | sed 's/\([^-]*\) - \([0-9]\)\([0-9][0-9]\)\(.*\)/\1 - S0\2E\3\4/g'`" ; done如果少于10个季节,这是可行的。
发布于 2014-04-23 11:24:50
下面的脚本将查找包含3个连续数字的字符串的所有.mp4。示例.111.mp4。它会将其转换为某种东西。S01E11.mp4。它还将排除任何示例文件。
find . ! -name "*sample*" -name '*.[0-9][0-9][0-9].*.mp4' -type f | while read filename; do mv -v "${filename}" "`echo $filename | sed -e 's/[0-9]/S0&E/;s/SS00E/S0/g'`";done;就像之前的脚本一样,它只有在少于10季的情况下才会起作用。
对于那些试图针对当前目录树进行个性化设置的用户,我建议您学习sed和find命令。它们非常强大,非常简单,并且允许您替换文件名中的任何字符串。
发布于 2014-04-23 13:16:42
以下是解决方案:
107,或用于第十季、剧集和高级find和bash技术的1002 ),例如:通过正则表达式匹配文件名的-regex主模式(而不是通配符模式,与-name)execdir一样,在与每个匹配文件相同的目录中执行命令(其中{}包含匹配的文件名only)bash脚本,它演示了正则表达式与=~的匹配,并通过内置的${BASH_REMATCH[@]}变量报告捕获组;命令替换( (${var:n[:m]}). )用零向左填充一个值;展开变量以提取子字符串$(...)
# The regular expression for matching filenames (without paths) of interest:
# Note that the regex is partitioned into 3 capture groups
# (parenthesized subexpressions) that span the entire filename:
# - everything BEFORE the season+episode specifier
# - the season+episode specifier,
# - everything AFTER.
# The ^ and $ anchors are NOT included, because they're supplied below.
fnameRegex='(.+ - )([0-9]{3,4})( - .+)'
# Find all files of interest in the current directory's subtree (`.`)
# and rename them. Replace `.` with the directory of interest.
# As is, the command will simply ECHO the `mv` (rename) commands.
# To perform the actual renaming, remove the `echo`.
find -E . \
-type f -regex ".+/${fnameRegex}\$" \
-execdir bash -c \
'[[ "{}" =~ ^'"$fnameRegex"'$ ]]; se=$(printf "%04s" "${BASH_REMATCH[2]}");
echo mv -v "{}" "${BASH_REMATCH[1]}S${se:0:2}E${se:2}${BASH_REMATCH[3]}"' \;https://stackoverflow.com/questions/14293519
复制相似问题