Rename folder | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Rename folder

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-15-2013
mhs mhs is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 December 2013, 1:09 PM EST
Posts: 23
Thanks: 15
Thanked 0 Times in 0 Posts
Rename folder

hi guys

i have a group of directory like these


Code:
p1( 15 - 16 )
p2( 17 -15 ) 
p1 ( 14 - 20 )
p2 ( 13 -17 )
..
.
.

directories contain numbers represent time
i want to rename all directories and change all numbers in directories' name .
for example

Code:
p1( 15 -16 ) will change to p1(14.40 - 15.50 )
p2( 17 -15 ) to p2( 16.50 - 14.50 )
p1 ( 14 -20 ) to p1( 13.50 - 19.50 )

and .....

what is the best way to do that???

Last edited by Scott; 09-15-2013 at 02:44 PM.. Reason: Code tags
Sponsored Links
    #2  
Old 09-15-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 31 August 2014, 4:07 PM EDT
Location: Aachen, Germany
Posts: 4,152
Thanks: 67
Thanked 992 Times in 940 Posts
That spec is a bit vague. Where do you get the times from? Is it always 10 min to the full hour? Try the mv command.
Sponsored Links
    #3  
Old 09-15-2013
mhs mhs is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 December 2013, 1:09 PM EST
Posts: 23
Thanks: 15
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
That spec is a bit vague. Where do you get the times from? Is it always 10 min to the full hour? Try the mv command.
named are fixed

for example
i have 100 directories like those

Code:
p1( 18 - 20 ) 
p3( 17 - 18 )
p1( 21 -23 )

and i want to rename those folder like that

Code:
p1( 18 - 20 ) to p1 ( 17.50 - 19.50 )
p3( 17 - 18 ) to p3( 16.50  - 17.50 )
p1( 21 -23 ) to p1( 20.50  -22.50 )

the only thing must be change is number is directories name !

how can i do that !! mv is not useful

Last edited by Scott; 09-15-2013 at 02:45 PM.. Reason: Code tags
    #4  
Old 09-15-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 31 August 2014, 4:07 PM EDT
Location: Aachen, Germany
Posts: 4,152
Thanks: 67
Thanked 992 Times in 940 Posts
Why is mv not useful?
Code:
mkdir "p1( 15 -16 )"
mv "p1( 15 -16 )" "p1(14.50 - 15.50)"
ls -d p*
p1(14.50 - 15.50)/

works!
Sponsored Links
    #5  
Old 09-15-2013
mhs mhs is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 December 2013, 1:09 PM EST
Posts: 23
Thanks: 15
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
Why is mv not useful?
Code:
mkdir "p1( 15 -16 )"
mv "p1( 15 -16 )" "p1(14.50 - 15.50)"
ls -d p*
p1(14.50 - 15.50)/

works!
!!!!!!!!!!!!!!!!!!!!! useful ??? )

first of all , directories created before and now i want to rename all of them !!
u just use simple mv to rename one directory !! how about 1000 directories with different number ????

why we use shell script . your work is like that to rename all directories manually !!!!!

i want to write shell script to grep for example 17 in all file names and change all of them to 16.50 and like that !!!
Sponsored Links
    #6  
Old 09-15-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 1 September 2014, 3:25 AM EDT
Location: Amsterdam
Posts: 9,371
Thanks: 272
Thanked 2,341 Times in 2,101 Posts
@mhs: Please do not leave people guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions being used.
Sponsored Links
    #7  
Old 09-15-2013
mhs mhs is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 December 2013, 1:09 PM EST
Posts: 23
Thanks: 15
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Scrutinizer View Post
@mhs: Please do not leave people guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions being used.
input directories

Code:
p8( 18.30 - 19 )
p1( 12 - 14 )
p4( 18  - 21 )
p1( 16 - 18 )
p2( 14  - 18 )
p1( 20 - 22 )
p1( 10 - 12 )
p3( 17  - 19 )
p2( 7.30 - 8 )
p4 ( 6.30 - 7.30 )
.
.
.
.

output directories

Code:
p8( 18.20 - 18.50 )
p1( 11.50 - 13.50 )
p4( 17.50  - 20.50 )
p1( 15.50 - 17.50 )
p2( 13.50  - 17.50 )
p1( 19.50 - 21.50 )
p1( 9.50 - 11.50 )
p3( 16.50  - 18.50 )
p2( 7.20 - 7.50 )
p4 ( 6.20 - 7.20 )
.
.
.
.

i wrote a simple code but i dont know how to expand that for this work

for example to change all 18 to 17.50


Code:
find . -type d  | while  read FILE
do
echo "$FILE" | grep 18 | sed 's/18/17.50/g'
done

and so on but my code does not make sense because 18 should be a counter from 1 to 23 and every time change in grep and sed to rename all directories .

any idea ????
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
looping through files, doing something, and rename in new folder bob101 UNIX for Dummies Questions & Answers 2 03-19-2012 03:44 PM
Using Vim or Ex to rename all files in a folder VimNewUser UNIX for Dummies Questions & Answers 5 09-07-2010 09:03 AM
Copy files from folder and rename them zeker Shell Programming and Scripting 4 12-24-2009 04:49 AM
rename all the files in a folder.. mac4rfree Shell Programming and Scripting 11 09-02-2009 04:27 AM
rename files in a folder tjmannonline UNIX for Dummies Questions & Answers 4 11-17-2008 11:31 AM



All times are GMT -4. The time now is 03:31 AM.