[NMLUG] Newbie Move/Rename question

Russell D. Miller nmlug@swcp.com
Sun, 4 Nov 2001 19:30:22 -0700 (MST)


> 
> 
> > for file in *.php; do mv $file ${file}3 ; done
> 
> When I read this, I was thinking mv xxxxx.php3 xxxxx.php, which
> would be a wee bit tougher.
> 
> How might we do the inverse problem.  using sed?

A simple perl script(see below for my first thought), or

for file in *.php3; do mv $file `echo $file | sed -e "s/php3/php/"`; done

I wouldn't have thought of using sed!  You just _got_ to love
Bash (and Perl!).

> 
> Award for the cleverest (simplest) solution goes to Russ!

Thanks!


#! /usr/bin/perl
# my first thought, called as
# junk *.php3

foreach $oldfile (@ARGV) {
        $newfile = $oldfile;
        $newfile =~ s/(.*).php3/\1.php/;
        @args = ( "mv", "$oldfile", "$newfile");
        system  @args;
}

Russ                 
------------------------------------------------------
To UNSUBSCRIBE send a message to nmlug-request@swcp.com
with only the word unsubscribe in the body.  More
information can be found at www.nmlug.org/info.html
-----------------------------------------------------