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
Moving multiple files and renaming them on the fly daemongk Shell Programming and Scripting 1 06-08-2007 10:36 AM
moving and renaming multiple files rocinante Shell Programming and Scripting 1 06-07-2007 05:20 PM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 01:40 AM
Renaming multiple files jxh461 Shell Programming and Scripting 4 04-01-2003 03:25 PM
renaming multiple files piltrafa UNIX for Dummies Questions & Answers 6 11-10-2001 09:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Renaming multiple files

Hi,

I have several hundred files I need to rename, and I'm would rather not hit F2 for each file individually to rename them.

Example of file:
large1961.jpg
What I need the file to be renamed as:
1961.jpg

I don't know what type of command I can execute within a shell script that would remove a specific unwanted part of the file name ("large") and leave the rest intact.

I am an obvious novice in shell scripting and would appreciate any help.
Thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 02-27-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 285
many ways...one is:

Code:
#  echo large1981.jpg | sed 's/large//'
1981.jpg
Reply With Quote
  #3  
Old 02-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Thanks.

So in order to actually rename the file, how could I take the output of that command and make it the final file name?
Reply With Quote
  #4  
Old 02-27-2008
HPAVC's Avatar
Registered User
 

Join Date: Feb 2008
Posts: 105
Code:
$ rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
... if you have rename I would go that route ...

Code:
rename 's/^large(.*)/$1/' large*.jpg
Reply With Quote
  #5  
Old 02-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 3
Thanks a lot. That did what I needed it to, and saved a lot of time on my part.

Could you explain the options you used in the command? I read the man page, but I'm not exactly sure what each parameter actually means.
Reply With Quote
  #6  
Old 02-27-2008
bushey1's Avatar
Registered User
 

Join Date: Feb 2008
Location: Florida
Posts: 2
oldtimer..... hope it helps..

if all of the files start with large or even a similar structure try this;

^large1967.*^1967.*
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:18 AM.


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

Content Relevant URLs by vBSEO 3.2.0