Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Joe
I think the following script will for for your pattern.

-- CUT HERE ---
#!/bin/bash

# To rename ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext

for file in $(ls ccna*ext | sort -rn -k 1.9)
do
let ix=$(echo $file | sed -e 's/.*pod//' -e 's/.pc..ext//')
let iy=$ix+1
newfile=$(echo $file | sed s/pod$ix/pod$iy/)
if [ -e $newfile ] ; then
# Shouldn't get here
echo Rename error of $newfile
continue
fi
mv $file $newfile
done
 CUT HERE 

James Mcphee wrote:
 assuming you're just trimming off ccna, pc1, and ext

 for i in $( ls )
 do
 mv $i $( echo $i | awk -F. '{ print $3 }' )
 done

 That would move them to pod# names.

 On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe 
 denn...@sdf.lonestar.org mailto:denn...@sdf.lonestar.org wrote:

 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't
 be asking this now. :-)

 Dennisk

 --
 Free as in Freedom
 Free Software Foundation
 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 mailto:PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss




 -- 
 James McPhee
 jmc...@gmail.com mailto:jmc...@gmail.com
 

 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Joe
That is what my script does. The sort -rn -k 1.9 says, sort reverse 
numeric with key 1 character position 9. I also check to make sure that 
another file is not dropped in there during processing of the script.


Dazed_75 wrote:


 On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe 
 denn...@sdf.lonestar.org mailto:denn...@sdf.lonestar.org wrote:

 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't
 be asking this now. :-)

 Dennisk

 --
 Free as in Freedom
 Free Software Foundation
 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 mailto:PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


 Actually, if the original specification is correct, probably none of 
 the solutions proposed is likely to work.  It appears that the target 
 name for the first rename is the same as the source for the second.  
 If this were true one would have to ensure that rename or move 
 operations were done in an order to avoid attempts to overwrite 
 existing names.

 -- 
 Man is the only animal that laughs and weeps, for he is the only 
 animal that is struck with the difference between what things are and 
 what they ought to be.
  - William Hazlitt
 

 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Stephen P Rufle
Is there a way to single step bash script to inspect what is going on? I
have preferred python for this reason. I write what I think will work in
eclipse and then run it once single stepping in debug mode to make sure
what I meant is what is actually happening.


Joe wrote:
 That is what my script does. The sort -rn -k 1.9 says, sort reverse 
 numeric with key 1 character position 9. I also check to make sure that 
 another file is not dropped in there during processing of the script.
 
 
 Dazed_75 wrote:

 On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe 
 denn...@sdf.lonestar.org mailto:denn...@sdf.lonestar.org wrote:

 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't
 be asking this now. :-)

 Dennisk

 --
 Free as in Freedom
 Free Software Foundation
 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 mailto:PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


 Actually, if the original specification is correct, probably none of 
 the solutions proposed is likely to work.  It appears that the target 
 name for the first rename is the same as the source for the second.  
 If this were true one would have to ensure that rename or move 
 operations were done in an order to avoid attempts to overwrite 
 existing names.

---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Eric Shubert
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

Stephen P Rufle wrote:
 Is there a way to single step bash script to inspect what is going on? I
 have preferred python for this reason. I write what I think will work in
 eclipse and then run it once single stepping in debug mode to make sure
 what I meant is what is actually happening.
 
 
 Joe wrote:
 That is what my script does. The sort -rn -k 1.9 says, sort reverse 
 numeric with key 1 character position 9. I also check to make sure that 
 another file is not dropped in there during processing of the script.


 Dazed_75 wrote:
 On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe 
 denn...@sdf.lonestar.org mailto:denn...@sdf.lonestar.org wrote:

 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't
 be asking this now. :-)

 Dennisk

 --
 Free as in Freedom
 Free Software Foundation
 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 mailto:PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


 Actually, if the original specification is correct, probably none of 
 the solutions proposed is likely to work.  It appears that the target 
 name for the first rename is the same as the source for the second.  
 If this were true one would have to ensure that rename or move 
 operations were done in an order to avoid attempts to overwrite 
 existing names.



-- 
-Eric 'shubes'

---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Dennis Kibbe
Actually, if the original specification is co=
rrect, probably none of the solutions proposed is likely to work.nbsp; It =
appears that the target name for the first rename is the same as the source=
 for the second.nbsp; If this were true one would have to ensure that rena=
me or move operations were done in an order to avoid attempts to overwrite =
existing names.

That's correct. So renaming needs to start at the end. (There are actually 24 
files in the directory.)

so renaming:

ccna.pod24.pc1.ext to ccna.pod25.pc1.ext

needs to happen before renaming:

ccna.pod23.pc1.ext to ccna.pod24.pc1.ext

and so on down to:

ccna.pod1.pc1.ext to ccna.pod2.pc1.ext

Dennisk

-- 
Free as in Freedom
Free Software Foundation
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Matt Graham
From: Stephen P Rufle stephen.p.ru...@cox.net
 Is there a way to single step bash script to inspect what is going on?

When I need copious debugging output from a bash script, I put set -x
at the top of the file.  When I need to check the syntax for a script,
I do sh -n file.sh.  Someone else already pointed out chapter 29 of
the bash scripting guide, which also has other bash debugging ideas.

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Alex Dean


On Feb 17, 2009, at 11:38 AM, Dennis Kibbe wrote:


Actually, if the original specification is co=
rrect, probably none of the solutions proposed is likely to  
work.nbsp; It =
appears that the target name for the first rename is the same as  
the source=
for the second.nbsp; If this were true one would have to ensure  
that rena=
me or move operations were done in an order to avoid attempts to  
overwrite =

existing names.


That's correct. So renaming needs to start at the end. (There are  
actually 24 files in the directory.)


so renaming:

ccna.pod24.pc1.ext to ccna.pod25.pc1.ext

needs to happen before renaming:

ccna.pod23.pc1.ext to ccna.pod24.pc1.ext

and so on down to:

ccna.pod1.pc1.ext to ccna.pod2.pc1.ext


Could you perhaps keep the original files in some other naming  
convention, and create symlinks in the ccna.podXX.pc1.ext format?  It  
might be easier to write a script, then, to :

 - remove all old symlinks
 - sort the original files by descending mtime
 - create new symlinks sequentially, 1-24.

This eliminates the need to parse the existing file names to figure  
out which sequence number they have.


Just a thought.

alex


PGP.sig
Description: This is a digitally signed message part
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

RE: bulk rename pod1 pod2 needed

2009-02-17 Thread Bob Elzer
What hasn't been answered is if this is open ended ?

Are you going to keep counting forever, thus  keeping on to 25, 26,  27.

Or can we cut it off at a particular number ? 24 ?

If we can cut it off then this simple solution would work

cd /the_directory
mv  ccna.pod23.pc1.ext to ccna.pod24.pc1.ext
mv  ccna.pod22.pc1.ext to ccna.pod23.pc1.ext
mv  ccna.pod21.pc1.ext to ccna.pod22.pc1.ext
.
.
mv  ccna.pod1.pc1.ext to ccna.pod2.pc1.ext
touch ccna.pod1.pcl.ext

If these are log files of some kind, you may want to look at the command
logrotate which is designed for such things.

Your initial message just asks how to rename the files, but in order to come
up with the correct solution you need to explain more on what you are trying
to accomplish.

Otherwise you get lots of different answers, all very valid, but
accomplishing different things.

For instance, if you move 1 to 2, then 2 to 3, and 3 to 4. You end up with 1
file that was originally 1, and could have been done  1 to 4.

Even after we know what you are trying to accomplish, the great thing is in
linux there are many ways to do it.



-Original Message-
From: plug-discuss-boun...@lists.plug.phoenix.az.us
[mailto:plug-discuss-boun...@lists.plug.phoenix.az.us] On Behalf Of Alex
Dean
Sent: Tuesday, February 17, 2009 12:47 PM
To: Main PLUG discussion list
Subject: Re: bulk rename pod1  pod2 needed


On Feb 17, 2009, at 11:38 AM, Dennis Kibbe wrote:

 Actually, if the original specification is co= rrect, probably none 
 of the solutions proposed is likely to work.nbsp; It = appears that 
 the target name for the first rename is the same as the source= for 
 the second.nbsp; If this were true one would have to ensure that 
 rena= me or move operations were done in an order to avoid attempts 
 to overwrite = existing names.

 That's correct. So renaming needs to start at the end. (There are 
 actually 24 files in the directory.)

 so renaming:

 ccna.pod24.pc1.ext to ccna.pod25.pc1.ext

 needs to happen before renaming:

 ccna.pod23.pc1.ext to ccna.pod24.pc1.ext

 and so on down to:

 ccna.pod1.pc1.ext to ccna.pod2.pc1.ext

Could you perhaps keep the original files in some other naming convention,
and create symlinks in the ccna.podXX.pc1.ext format?  It might be easier to
write a script, then, to :
  - remove all old symlinks
  - sort the original files by descending mtime
  - create new symlinks sequentially, 1-24.

This eliminates the need to parse the existing file names to figure out
which sequence number they have.

Just a thought.

alex

---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-17 Thread Kevin Spencer
On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe denn...@sdf.lonestar.org wrote:
 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't be asking 
 this now. :-)

 Dennisk

A quick Perl solution.

#!/usr/bin/perl -w

use strict;

my $indir = '/path-to/the-files';

opendir(DIRECTORY, $indir) || die Could not open $indir - $!\n;
my @files = grep /\.ext$/, readdir(DIRECTORY);
closedir(DIRECTORY);
@files = reverse(sort(@files));
foreach my $oldfilename (@files) {
if ($oldfilename =~ /^ccna.pod(\d+)/) {
my $sequence = $1 + 1;
my $newfilename = 'ccna.pod' . $sequence .'.pc1.ext';
rename($oldfilename, $newfilename) || die Could not rename
$oldfilename to $newfilename - $!\n;
}
}

Kevin.
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


Re: bulk rename pod1 pod2 needed

2009-02-16 Thread James Mcphee
assuming you're just trimming off ccna, pc1, and ext

for i in $( ls )
do
mv $i $( echo $i | awk -F. '{ print $3 }' )
done

That would move them to pod# names.

On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe denn...@sdf.lonestar.orgwrote:

 Can someone suggest a way to rename a directory of files like this:

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext
 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 and so on.

 (Aside: Hans, if I were able to take your scripting class I won't be asking
 this now. :-)

 Dennisk

 --
 Free as in Freedom
 Free Software Foundation
 ---
 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
 To subscribe, unsubscribe, or to change your mail settings:
 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss




-- 
James McPhee
jmc...@gmail.com
---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

RE: bulk rename pod1 pod2 needed

2009-02-16 Thread Lisa Kachold

This will increment the second field in the file for each file in the directory 
named *.ext.  

The last digit before dot will increment by 1; yet if it is 9 it should become 
0.

[Caveat - untested...(use carefully)]:

ls *.ext |
awk -F. '{s=substr($2,length($2))
s++;s=s==10?0:s
printf(mv %s %s%s.%s\n, $0, substr($2,1,length($2)-1), s, $3)}
' | sh


obnosis.com | wiki.obnosis.com| (503)754-4452
PLUG HACKFESTS 2nd Saturday Each mo...@noon - 3PM

Date: Mon, 16 Feb 2009 17:36:58 -0700
Subject: Re: bulk rename pod1  pod2 needed
From: jmc...@gmail.com
To: denn...@member.fsf.org; plug-discuss@lists.plug.phoenix.az.us

assuming you're just trimming off ccna, pc1, and ext

for i in $( ls )
do
mv $i $( echo $i | awk -F. '{ print $3 }' )
done

That would move them to pod# names.


On Mon, Feb 16, 2009 at 5:33 PM, Dennis Kibbe denn...@sdf.lonestar.org wrote:

Can someone suggest a way to rename a directory of files like this:



ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext

ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext



and so on.



(Aside: Hans, if I were able to take your scripting class I won't be asking 
this now. :-)



Dennisk



--

Free as in Freedom

Free Software Foundation

---

PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us

To subscribe, unsubscribe, or to change your mail settings:

http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



-- 
James McPhee
jmc...@gmail.com

_
Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

RE: bulk rename pod1 pod2 needed

2009-02-16 Thread Lisa Kachold

Course 'man rename' will work also




obnosis.com | wiki.obnosis.com| (503)754-4452

PLUG HACKFESTS 2nd Saturday Each mo...@noon - 3PM









 Date: Tue, 17 Feb 2009 00:33:38 +

 From: denn...@sdf.lonestar.org

 To: plug-discuss@lists.plug.phoenix.az.us

 Subject: bulk rename pod1  pod2 needed

 

 Can someone suggest a way to rename a directory of files like this:

 

 ccna.pod1.pc1.ext is renamed to ccna.pod2.pc1.ext

 ccna.pod2.pc1.ext is renamed to ccna.pod3.pc1.ext

 

 and so on.

 

 (Aside: Hans, if I were able to take your scripting class I won't be asking 
 this now. :-)

 

 Dennisk

 

 -- 

 Free as in Freedom

 Free Software Foundation

 ---

 PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us

 To subscribe, unsubscribe, or to change your mail settings:

 http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss


_
See how Windows connects the people, information, and fun that are part of your 
life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/---
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss