【问题标题】:How to rename files by reducing the number value within filenames by the same amount for each file如何通过将每个文件的文件名中的数字值减少相同的数量来重命名文件
【发布时间】:2023-02-13 21:36:20
【问题描述】:

我有一个这种格式的文件列表:

"stuff that happened B05T300 today.png"
"stuff that happened B05T301 today.png"
"stuff that happened B05T302 today.png"
"stuff that happened B05T303 today.png"

我想以两种方式重命名文件。

1. B05 needs to become B01
2. T300 needs to become T001, T301 -> T002, etc...  essentially the Txxx will be xxx - 299. 
Potentially also have the 0 chars removed immediately after the T.  ie. T1, T10

【问题讨论】:

    标签: awk rename


    【解决方案1】:

    使用Perl's rename

    $ rename -n 's/B05T/B01T/;s/(?<=B01T)(d+)/sprintf "%03d", ($1 - 299)/e' *.png
    rename(stuff that happened B05T300 today.png, stuff that happened B01T001 today.png)
    rename(stuff that happened B05T301 today.png, stuff that happened B01T002 today.png)
    rename(stuff that happened B05T302 today.png, stuff that happened B01T003 today.png)
    rename(stuff that happened B05T303 today.png, stuff that happened B01T004 today.png)
    

    当输出看起来令人满意时,删除-n(又名dry-run)。

    【讨论】:

      猜你喜欢
      • 2013-06-15
      • 2012-06-30
      • 2018-04-10
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 2012-06-01
      • 2014-06-22
      相关资源
      最近更新 更多