From: James Egan on
I'm trying to use the perl "rename" script to rename batches of files.
So if the files are say:

0123.mov
0124.mov
0125.mov


I want to rename something like:

birthday-01.mov
birthday-02.mov
birthday-03.mov

I've been experimenting with the rename script like this:

rename s/\..+$/Birthday-01/ *


Can this be done with regular expressions only? I was thinking of trying
to use the seq command to get the numeric sequence part of the file names.

-Thanks
From: Ilya Zakharevich on
On 2010-05-22, James Egan <jegan473(a)comcast.net> wrote:
> 0123.mov
> 0124.mov
> 0125.mov

> I want to rename something like:

> birthday-01.mov
> birthday-02.mov
> birthday-03.mov

> Can this be done with regular expressions only?

Regular expressions may contain arbitrary code. With pfind
(ilyaz.org/software/tmp) which is a much improved version of `rename',
I would do

pfind -nosubdir '-var=$c' . '++$c; s/^[^.]*/birthday-$c/'

Not what you want? Add a sprintf... (I would do it outside s///, but
one can do it inside too with s///e; then one can do ++$c there
too...)

Hope this helps,
Ilya
From: J�rgen Exner on
James Egan <jegan473(a)comcast.net> wrote:
>I'm trying to use the perl "rename" script to rename batches of files.

What rename script? Did you mean rename command?

>So if the files are say:
>
>0123.mov
>0124.mov
>0125.mov
>
>
>I want to rename something like:
>
>birthday-01.mov
>birthday-02.mov
>birthday-03.mov

Is there a relationship between the number 0124 the number 02? If so
which one?
Or do you just want to have consecutive numbers in your new filenames
without any relationship to the numbers in the old files?

If so then (untested)
my @oldnames = ..... #whatever way you get the old names
for (my $i = (1..(a)oldnames)) {
rename $oldnames[$i-1] "birthday-0$i.mov";
}

>Can this be done with regular expressions only? I was thinking of trying
>to use the seq command to get the numeric sequence part of the file names.

No, regular expressions match text, they don't rename a file.

jue
From: J�rgen Exner on
Ilya Zakharevich <nospam-abuse(a)ilyaz.org> wrote:
>On 2010-05-22, James Egan <jegan473(a)comcast.net> wrote:
>> 0123.mov
>> 0124.mov
>> 0125.mov
>
>> I want to rename something like:
>
>> birthday-01.mov
>> birthday-02.mov
>> birthday-03.mov
>
>> Can this be done with regular expressions only?
>
>Regular expressions may contain arbitrary code.

Really? Double-checking now.... Yes, it appears you are right:

"(?{ code })"
WARNING: This extended regular expression feature is
considered experimental, and may be changed without notice

>With pfind
>(ilyaz.org/software/tmp) which is a much improved version of `rename',
>I would do
>
> pfind -nosubdir '-var=$c' . '++$c; s/^[^.]*/birthday-$c/'

There is no code in this RE.

>Not what you want? Add a sprintf... (I would do it outside s///, but
>one can do it inside too with s///e; then one can do ++$c there
>too...)

The /e modifier doesnt' affect the regular expression but only the
substitution string.

jue
From: Tad McClellan on
James Egan <jegan473(a)comcast.net> wrote:

> I'm trying to use the perl "rename" script to rename batches of files.


What is "the perl rename script"?

I have never heard of it.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.