C
Chris Ellison
Hi,
"Larry's filename fixer"
------filename: rename-------------
#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
----------------------------------
I have a bunch of files 001.txt, 002.txt, 055.txt, 099.txt,... and
would like to increment them using the above script.
So, I was thinking something like this:
rename 's/(\d{3})/something/' *
Though, I don't know how to accomplish the "something".
I was thinking that it could be done with backreferencing:
$1+increment
but I don't know how to do operations within a regular expression.
Any suggestions?
"Larry's filename fixer"
------filename: rename-------------
#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
----------------------------------
I have a bunch of files 001.txt, 002.txt, 055.txt, 099.txt,... and
would like to increment them using the above script.
So, I was thinking something like this:
rename 's/(\d{3})/something/' *
Though, I don't know how to accomplish the "something".
I was thinking that it could be done with backreferencing:
$1+increment
but I don't know how to do operations within a regular expression.
Any suggestions?