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

In reply to Re: Private Utilities by Anonymous Monk
in thread Private Utilities by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.