0

我被困在这里了。请帮忙。

我有大量文件,命名如下:

plot_[0-9]*\.?[0-9]+\.png

例如plot_.0012.pngplot_1.12.png

有没有办法将它重命名为plot_{5 digits}.png, likeplot_00012.pngplot_11200.png

任何帮助都会非常棒!

问候,于尔根

4

1 回答 1

0

Here is a way to do it in Perl:

#!/usr/bin/perl
use strict;
use warnings;
use 5.10.1;
use Data::Dumper;

while(<DATA>) {
    chomp;
    print "$_ --> ";
    s/^(plot_)(\d*)\.?(\d+)(\.png)$/$1 . '0'x(6-length("$2+$3")) . $2 . $3 . $4/e;
    say;
}

__DATA__
plot_.0012.png
plot_1.12.png
plot_12.023.png
plot_1.png

Output:

plot_.0012.png --> plot_00012.png
plot_1.12.png --> plot_00112.png
plot_12.023.png --> plot_12023.png
plot_1.png --> plot_00001.png
于 2011-01-07T09:38:31.717 回答