[NMLUG] Newbie Move/Rename question

nmlug@swcp.com nmlug@swcp.com
Sun, 4 Nov 2001 19:50:00 -0700 (MST)


A more cryptic solution ;) ...

ls *.php3 | perl -pnle 's/(.*)3$/mv ${1}3 $1/' | sh

--
Sincerely, Sarang (sarang@sarangworld.com)
AOL Instant Messenger ID: JavaMath

On Sun, 4 Nov 2001, Russell D. Miller wrote:

> Date: Sun, 4 Nov 2001 19:30:22 -0700 (MST)
> From: Russell D. Miller <rdmille@thuntek.net>
> Reply-To: nmlug@swcp.com
> To: nmlug@swcp.com
> Subject: Re: [NMLUG] Newbie Move/Rename question
>
> >
> >
> > > 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
> -----------------------------------------------------
>
>

------------------------------------------------------
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
-----------------------------------------------------