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 common suffix er_ashu UNIX for Dummies Questions & Answers 1 09-28-2007 07:52 AM
Rename part of multiple files sajjad02 Shell Programming and Scripting 4 02-22-2005 09:30 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 04-22-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 518
Stumble this Post!
how to rename multiple files with a single command

Hi

I have following list of files at a path:

01.AR.asset
01.AR.index
01.AR.asset.vf
01.AR.asset.xv

I want to rename all these files as follows:

73.AR.asset.Z
73.AR.index.Z
73.AR.asset.vf.Z
73.AR.asset.xv.Z

Can any body give me a single command to acheive the above results.

Thnx & Regards,
Tayyab
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-22-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,426
Stumble this Post!
Yeah...but it is a rather complex command and requires a powerful shell (I'm using ksh). We need a pattern that will match those 4 files and only those 4 files. I will assume that 01.AR.* will do that.
Code:
$ ls *AR*
01.AR.asset     01.AR.asset.vf  01.AR.asset.xv  01.AR.index
$ for i in 01.AR.* ; do mv $i 73${i#01}.Z ; done
$ ls *AR*
73.AR.asset.Z           73.AR.asset.xv.Z
73.AR.asset.vf.Z        73.AR.index.Z
$
Reply With Quote
  #3 (permalink)  
Old 04-23-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 518
Stumble this Post!
Thanks Perderabo for your reply. It worked perfectly. Can you pls explain me the 73${i#01} part of this command. It'll be a great favor. Thnx & Rgrds, Tayyab
Reply With Quote
  #4 (permalink)  
Old 04-23-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,426
Stumble this Post!
${i} is the value of the variable i
${i#01} is the value of the variable i with any leading "01" removed

That leading 73 is just like the trailing .Z which you didn't ask about. We are just tacking some constant text on to both ends of the value of the variable.
Reply With Quote
  #5 (permalink)  
Old 04-23-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 518
Stumble this Post!
I got it, Thanks for your explanation. This command will save a lot of my time.

Regards,
Tayyab
Reply With Quote
  #6 (permalink)  
Old 03-18-2008
Registered User
 

Join Date: Mar 2008
Posts: 24
Stumble this Post!
rename multiple files

Hi tyub,

This is Antony. Do you remember me.? you want to use this in Kerridge AR module.

its like this

for i in *
do
mv $i $i.Z
done

Hopefully this helps you..

Regards,
Antony
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:53 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