在文件名中间添加0

用户107459
$ ls
pro2e_u01_txt_vocabulaire_11_descriptiveadjectives.mp3
pro2e_u01_txt_vocabulaire_12_nationality.mp3
pro2e_u01_txt_vocabulaire_1_campus.mp3
pro2e_u01_txt_vocabulaire_2_personnes.mp3
pro2e_u01_txt_vocabulaire_3_presentations.mp3
pro2e_u01_txt_vocabulaire_4_identifier.mp3
pro2e_u01_txt_vocabulaire_5_bonjouraurevoir.mp3
pro2e_u01_txt_vocabulaire_6_commentcava.mp3
pro2e_u01_txt_vocabulaire_7_expressionspolitesse.mp3

我想在中间的数字前添加“ 0”,以便它们按以下顺序排序

$ ls -v
pro2e_u01_txt_vocabulaire_1_campus.mp3
pro2e_u01_txt_vocabulaire_2_personnes.mp3
pro2e_u01_txt_vocabulaire_3_presentations.mp3
pro2e_u01_txt_vocabulaire_4_identifier.mp3
pro2e_u01_txt_vocabulaire_5_bonjouraurevoir.mp3
pro2e_u01_txt_vocabulaire_6_commentcava.mp3
pro2e_u01_txt_vocabulaire_7_expressionspolitesse.mp3
pro2e_u01_txt_vocabulaire_11_descriptiveadjectives.mp3
pro2e_u01_txt_vocabulaire_12_nationality.mp3

我到目前为止所拥有的是

$ for i in *.mp3; do echo ${i/_[0-9]_/_0¿_}; done
pro2e_u01_txt_vocabulaire_11_descriptiveadjectives.mp3
pro2e_u01_txt_vocabulaire_12_nationality.mp3
pro2e_u01_txt_vocabulaire_0¿_campus.mp3
pro2e_u01_txt_vocabulaire_0¿_personnes.mp3
pro2e_u01_txt_vocabulaire_0¿_presentations.mp3
pro2e_u01_txt_vocabulaire_0¿_identifier.mp3
pro2e_u01_txt_vocabulaire_0¿_bonjouraurevoir.mp3
pro2e_u01_txt_vocabulaire_0¿_commentcava.mp3
pro2e_u01_txt_vocabulaire_0¿_expressionspolitesse.mp3

我不知道应该用'?'代替什么,以便匹配出现[0-9]的数字出现。

贾尼斯(Janis)

有时,一个特定的解决方案就足够了。例如在当前情况下,您可以标识要考虑的文件子集的模式(例如/_[0-9]_/),并根据唯一标识的前缀添加前导零(例如/re_/)。将所有内容放在一起将是:

for f in *_[0-9]_*.mp3 ; do mv -i "${f}" "${f/re_/re_0}" ; done

对于您要求的预检查,您可以echo在前面添加一个mv

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

cmd在文件名中间插入文本

来自分类Dev

从文件名中间删除\ r字符

来自分类Dev

Nifi:捕获文件名的中间部分

来自分类Dev

将前导零添加到非顺序文件名的中间

来自分类Dev

Shell - 如何重命名文件名中间的文件?

来自分类Dev

将文件名的中间部分移到前面

来自分类Dev

如何让zsh的补全工作在文件名中间?

来自分类Dev

在文件名中添加序列前缀

来自分类Dev

在多个文件名的末尾添加“文本”

来自分类Dev

在网址中添加文件名

来自分类Dev

在数组中添加文件名

来自分类Dev

在RollingFileAppender文件的文件名中添加日期

来自分类Dev

使用Shell添加文件名合并多个文件

来自分类Dev

修改一些文件以添加文件名

来自分类Dev

在文件夹中文件名的开头添加序号

来自分类Dev

如何重命名文件,同时保持文件名中间位置不变

来自分类Dev

如何区分两个目录中的文件名(不写入中间文件)?

来自分类Dev

将文件重命名为文件名的前缀和中间部分

来自分类Dev

替换文件路径的中间位置,同时保留文件名末尾?

来自分类Dev

使用Gulp向文件名添加时间戳

来自分类Dev

转义git在文件名中添加前导“-”?

来自分类Dev

Logstash:如何将文件名添加为字段?

来自分类Dev

bash shell:更改多个文件名以添加前导零

来自分类Dev

在文件名前批量添加字符串

来自分类Dev

重击以匹配文件名中的模式,然后添加/编辑

来自分类Dev

awk / sed文件名添加到模式匹配

来自分类Dev

使用Powershell循环添加到文件名

来自分类Dev

在c中的文件名中添加日期和时间

来自分类Dev

Perl在文件名中添加日期/时间