Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Private Utilities

by Anonymous Monk
on Nov 30, 2005 at 19:50 UTC ( [id://513075]=note: print w/replies, xml ) Need Help??


in reply to Private Utilities

A quick and dirty rename command for UNIX: it looks simple, but is quite handy. Also, similar little utilities for deleting all the empty files (including empty gzipped files) in a directory, copying with rename, and so forth...
%cat rename.pl #!/usr/bin/perl =head1 SYNOPSIS rename.pl '<pattern from>/<pattern to>' <filenames> =head1 DESCRIPTION Renames the files listed as <filenames> after performing the substitut +ion using the standard perl regular expression pattern from and to. =head1 EXAMPLES rename.pl 'ready/done' file1-ready file2-ready_to_go renames "file1-ready" to "file1-done" and "file2-ready_to_go" to "file2-done_to_go" =cut use strict; use warnings; my $file; my $old; my $pattern; my $command; unless( @ARGV >= 2) { print "Usage: rename \"patternfrom/to\" <filenames>\n"; exit(1); } # end argument check $pattern = shift(@ARGV); foreach $file (@ARGV) { $old=$file; $pattern .= "/" unless( $pattern =~ m#.*?/.*?/$# ); $command = "\$file =~ s/$pattern"; eval $command; if ( $@ ) { print STDERR "$@"; } # end eval failed check rename($old,$file); } # end rename loop

Replies are listed 'Best First'.
Re^2: Private Utilities
by eyepopslikeamosquito (Archbishop) on Nov 30, 2005 at 23:30 UTC

      Note also my improvements on it: rename 0.3 - now with two extra cupholders

      (The version on my disk is a bit better in some ways, but has grown messily, and I have no clear idea about how to clean it up…)

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://513075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found