$ 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]的数字出现。
有时,一个特定的解决方案就足够了。例如在当前情况下,您可以标识要考虑的文件子集的模式(例如/_[0-9]_/
),并根据唯一标识的前缀添加前导零(例如/re_/
)。将所有内容放在一起将是:
for f in *_[0-9]_*.mp3 ; do mv -i "${f}" "${f/re_/re_0}" ; done
对于您要求的预检查,您可以echo
在前面添加一个mv
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句