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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hello - new here - bash script - need to rename and zip files. Aixia Shell Programming and Scripting 1 07-15-2008 03:48 PM
simple count script outputting mass errors aspect_p Shell Programming and Scripting 2 03-09-2008 07:58 PM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 04:20 AM
Mass Copy/rename lwilsonFG UNIX for Dummies Questions & Answers 6 11-03-2005 06:55 AM
Easy way to mass rename files? Thermopylae UNIX for Dummies Questions & Answers 17 11-18-2002 01:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2008
audiophile audiophile is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 27
bash script to rename in mass

Basically, I have a huge amount of files (ripped audiobooks) that all have the same garbage in their filenames. I'm wondering how to go about writing a bash script to mass rename them. Example filenames as they stand now:


Code:
The First CD - 1x01 - Title 1.mp3
The First CD - 1x02 - Title 2.mp3
The First CD - 1x03 - Title 3.mp3
The First CD - 1x04 - Title 4.mp3

I'd like to have the script ask me what needs to be removed and then do it.

In this case, I want to remove the text: "The First CD - "
The output of the directory above would then be:


Code:
1x01 - Title 1.mp3
1x02 - Title 2.mp3
1x03 - Title 3.mp3
1x04 - Title 4.mp3

Thanks all!
  #2 (permalink)  
Old 09-26-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,440

Code:
for i in *.mp3
do 
   echo mv "$i" "${i/The First CD - /}"
done

If that's what you want, just remove the echo
  #3 (permalink)  
Old 09-26-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926
If you have rename:


Code:
rename 'The First CD - ' '' *.mp3

  #4 (permalink)  
Old 09-26-2008
audiophile audiophile is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 27
Killer! Thanks for the suggestions guys. I found rename.pl from this site.
  #5 (permalink)  
Old 09-26-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,556
if you have Python , you can use this script.
eg usage

Code:
# ls -1 *Title*mp3
The First CD - 1x01 - Title 1.mp3
The First CD - 1x02 - Title 2.mp3

# filerenamer.py -p "The First CD - " -e "" -l "*Title*mp3" #use -l to check
==>>>>  [ /home/The First CD - 1x01 - Title 1.mp3 ]==>[ /home/1x01 - Title 1.mp3 ]
==>>>>  [ /home/The First CD - 1x02 - Title 2.mp3 ]==>[ /home/1x02 - Title 2.mp3 ]

# filerenamer.py -p "The First CD - " -e ""  "*Title*mp3" #remove -l to commit
/home/The First CD - 1x01 - Title 1.mp3  is renamed to  /home/1x01 - Title 1.mp3
/home/The First CD - 1x02 - Title 2.mp3  is renamed to  /home/1x02 - Title 2.mp3

# ls -1 *Title*mp3
1x01 - Title 1.mp3
1x02 - Title 2.mp3

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0