linux文件名只保留数字,linux - Linux - 如何在文件名中间添加增量数字? [关闭] - SO中文参考 - www.soinside.com...

Linux实用程序rename只是一个简单的工具。使用正则表达式的更高级工具是perl-rename,它通常单独安装。但它仍然无法解决您的问题。

对于任何更复杂的事情,我通常会尝试编写一个小的bash for loop。

例如。此脚本应该适用于您的问题:

# for every file ending with .mkv

for f in *.mkv; do

# transform the filename using sed, so that character '|' character will separate episode number from the lest of the filename (so it can be extracted)

# e.g.

# 'ShowName - S00E01 - Episode Name.mkv' will be

# 'ShowName - S00E|01| - Episode Name.mkv'

# Then read such string to three variables:

# prefix enum and suffix splitting on '|' character

IFS='|' read -r prefix enum suffix <

# newfilename consist of prefix, calculated episode number and the rest of the filename

# i assumed you want to add 19 to episode number

# it may be also a good idea to move files to another directory, to avoid unintentional overwriting of existing files

# you may also consider using -n/--no-clobber or --backup options to mv

newf="another_directory/${prefix}$(printf "%02d" "$((enum-1+20))")${suffix}"

# move "$f" to "$newf"

# filenames have special characters (spaces), so remember about qoutes

echo "'$f' -> '$newf'"

mv -v "$f" "$newf"

done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值