The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rename multiple files antointoronto Shell Programming and Scripting 13 03-20-2008 06:16 AM
how to rename multiple files with a single command tayyabq8 Shell Programming and Scripting 5 03-18-2008 12:04 PM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 10:41 AM
Rename multiple files luiz_fer10 UNIX for Dummies Questions & Answers 7 06-11-2002 05:06 AM
Rename Multiple Files molonede UNIX for Dummies Questions & Answers 1 11-14-2000 08:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2005
Registered User
 

Join Date: Sep 2004
Posts: 8
Stumble this Post!
Rename part of multiple files

Hello, I have about 200 files named like script1234_test.sh script3434_test.sh and so on... I am trying to write a script that will rename those files from test to dev, keeping the rest of the file name intact. Could anyone help? Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-21-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
try this ... NOT tested.

Code:
for filename in `ls script*_test*sh`
do
   newfilename=`echo $filename | sed 's/test/dev/'
   mv $filename $newfilename
  
done
Reply With Quote
  #3 (permalink)  
Old 02-21-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
UUOls
Code:
for filename in script*_test*sh
Reply With Quote
  #4 (permalink)  
Old 02-21-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
for i in script*_test.sh; do mv $i ${i%test.sh}dev.sh; done
Reply With Quote
  #5 (permalink)  
Old 02-22-2005
Registered User
 

Join Date: Sep 2004
Posts: 8
Stumble this Post!
Thanks for your input... This works...

for old in *test*.sh
do
new=`echo $old | sed 's/test/dev/g'`
mv $old $new
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0