Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Rename with Perl compatible regular experssions?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
gercina
n00b
n00b


Joined: 13 Sep 2007
Posts: 15

PostPosted: Fri Apr 25, 2008 9:02 am    Post subject: Rename with Perl compatible regular experssions? Reply with quote

I've installed "sys-apps/rename" but I can't use it with perl compatible regular experssions.
Is it a way to use this application with perl compatible regular experssions?
Or does exist any other easy to use command line renamer with I could use perl compatible regular experssions?
Back to top
View user's profile Send private message
alex.blackbit
Advocate
Advocate


Joined: 26 Jul 2005
Posts: 2397

PostPosted: Fri Apr 25, 2008 8:37 pm    Post subject: Reply with quote

if you are used to code in perl that should be possible to do in a few lines.
all you have to do is a loop in which you process all the wanted files.
the condition is the pcre, the body is the renaming.
Back to top
View user's profile Send private message
wassp
n00b
n00b


Joined: 14 Nov 2002
Posts: 7
Location: The Netherlands

PostPosted: Sun Apr 27, 2008 2:17 pm    Post subject: Reply with quote

Something like this:
http://www.perlmonks.org/?displaytype=displaycode;node_id=302113

The script above is a more elaborate version of this perl script (but roughly the same functionality you want):
Code:

#!/usr/bin/perl

# Usage: Rename perlexpr [files]

($op = shift) || die "Usage: Rename perlexpr [filenames]\n";
if (!@ARGV) {
    @ARGV = <STDIN>;
    chop(@ARGV);
}
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum