For the more general case, there's Larry's filename fixer, from the Perl Cookbook (and I'm sure I've seen it in print elsewhere, too):
#!/usr/bin/perl # -w switch is off bc HERE docs cause erroneous messages to be display +ed under Cygwin #From the Perl Cookbook, Ch. 9.9 # rename - Larry's filename fixer $help = <<EOF; Usage: rename expr [files] This script's first argument is Perl code that alters the filename (st +ored in \$_ ) to reflect how you want the file renamed. It can do thi +s because it uses an eval to do the hard work. It also skips rename c +alls when the filename is untouched. This lets you simply use wildcar +ds like rename EXPR * instead of making long lists of filenames. Here are five examples of calling the rename program from your shell: % rename 's/\.orig$//' *.orig % rename 'tr/A-Z/a-z/ unless /^Make/' * % rename '$_ .= ".bad"' *.f % rename 'print "$_: "; s/foo/bar/ if <STDIN> =~ /^y/i' * % find /tmp -name '*~' -print | rename 's/^(.+)~$/.#$1/' The first shell command removes a trailing ".orig" from each filename. The second converts uppercase to lowercase. Because a translation is u +sed rather than the lc function, this conversion won't be locale-awar +e. To fix that, you'd have to write: % rename 'use locale; $_ = lc($_) unless /^Make/' * The third appends ".bad" to each Fortran file ending in ".f", somethin +g a lot of us have wanted to do for a long time. The fourth prompts the user for the change. Each file's name is printe +d to standard output and a response is read from standard input. If t +he user types something starting with a "y" or "Y", any "foo" in the +filename is changed to "bar". The fifth uses find to locate files in /tmp that end with a tilde. It +renames these so that instead of ending with a tilde, they start with + a dot and a pound sign. In effect, this switches between two common +conventions for backup files EOF $op = shift or die $help; chomp(@ARGV = <STDIN>) unless @ARGV; for (@ARGV) { $was = $_; eval $op; die $@ if $@; rename($was,$_) unless $was eq $_; }
(Notice that about 90% of that is comments and usage.)

Using that script, you can say:

rename 's/ABC //' *.doc
to rename all files with 'ABC ' in the name.

In reply to Re: Simple Perl file rename by hilitai
in thread Simple Perl file rename by Anonymous Monk

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.