here's a script that Unix Guru Universe sent out today as a "good" script to use to rename a bunch of files with a simple regex as an ARG to determine how to rename. thought it may be fun to GOLF it =)

#!/usr/bin/perl # rename: renames files according to the expr given on the command lin +e. # The expr will usually be a 's' or 'y' command, but can be any valid # perl command if it makes sense. Takes a list of files to work on or # defaults to '*' in the current directory. # e.g. # rename 's/\.flip$/.flop/' # rename *.flip to *.flop # rename s/flip/flop/ # rename *flip* to *flop* # rename 's/^s\.(.*)/$1.X/' # switch sccs filenames around # rename 's/$/.orig/' */*.[ch] # add .orig to your source fil +es in */ # rename 'y/A-Z/a-z/' # lowercase all filenames in . # rename 'y/A-Z/a-z/ if -B' # same, but just binaries! # rename chop *~ # restore all ~ backup files use Getopt::Std; my ($subst, $name); if (!&getopts("nfq") || $#ARGV == -1) { die "Usage: rename [-fnq] <perl expression> [file file...] -f : Force the new filename even if it exists already -n : Just print what would happen, but don't do the command -q : Don't print the files as they are renamed e.g. : rename 's/\.c/.c.old/' * rename -q 'y/A-Z/a-z/' *\n"; } $subst = shift; # Get perl command to work on @ARGV = <*> if $#ARGV < 0; # Default to complete directory foreach $name (@ARGV) { $_ = $name; eval "$subst;"; die $@ if $@; next if -e $_ && !$opt_f; # Skip if the file exists if asked to. mext if $_ eq $name; if ($opt_n) { print "mv $name $_\n"; next; } print "mv $name $_\n" if !$opt_q; rename($name,$_) or warn "Can't rename $name to $_, $!\n"; }

We speak the way we breathe. --Fugazi


In reply to UGU file rename script (GOLF?) by jptxs

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.