The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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 07:16 AM
how to rename multiple files with a single command tayyabq8 Shell Programming and Scripting 5 03-18-2008 01:04 PM
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 10:30 AM
Rename Multiple Files molonede UNIX for Dummies Questions & Answers 1 11-14-2000 09:40 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-10-2002
Registered User
 

Join Date: May 2002
Location: Campinas, Brazil
Posts: 20
Question Rename multiple files

Hello,

I want to rename multiple files at a time and I don't know how to do it.

I have various ".mp3" files, like "band name - music name.mp3" and I want to remove the "band name" from all files.

Anybody knows how to do it using shell script or sed or even perl?

Thanks
Forum Sponsor
  #2  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
If you do a search for rename and files, you will come up with the following and more which should take care of your problem:
Rename files
  #3  
Old 06-10-2002
Registered User
 

Join Date: May 2002
Location: Campinas, Brazil
Posts: 20
Hello,

Thanks for your help but my problem it's a quite different for that answers. I don't want to rename the extensions of my files. I want to change the name of my files like this:

"first name - second name.mp3" to "second name.mp3"

Thanks
  #4  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
But did you bother to do the search yourself? If so, you would have found the rest of what you needed.
more renamed files

Part of the learning process is to do - not just have it done for you. This will give you almost what you are looking for....the PROD to TEST will help but YOU still have to think. It's the only way to learn.
  #5  
Old 06-10-2002
Registered User
 

Join Date: May 2002
Location: Campinas, Brazil
Posts: 20
I executed the script:

for file in *.mp3
do
newfile=`echo $file | sed 's/black\ sabbath\ //g'`
file=`echo $file | sed 's/ /_/g'`
mv $file $newfile
done

and the result was:

mv: cannot access black_sabbath_music1.mp3
mv: cannot access black_sabbath_music2.mp3
mv: cannot access black_sabbath_music3.mp3
mv: cannot access black_sabbath_music4.mp3

my files are:

black sabbath music1.mp3
black sabbath music2.mp3
black sabbath music3.mp3
black sabbath music4.mp3

What is wrong?
  #6  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Remember, your problem was a little different.
I mentioned that it would help, not be your cure all.

Since you have spaces in your file names (at least according to your post), look at this and realize that the echo command would work the same as the mv command. Both need the quotes for files with spaces in the name.

for file in *.mp3
do
newfile=`echo $file | awk -F" " '{print $3}'`
echo "$file"
echo "$newfile"
done
  #7  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Sorry, should have kept your original script -

The problem with your script was you changed the variable file
for file in *.mp3
do
newfile=`echo $file | sed 's/black\ sabbath\ //g'`
file=`echo $file | sed 's/ /_/g'`
mv $file $newfile
done

If you had not changed what you were originally looking for, it may have worked - you also needed some quotes to move the files

for file in *.mp3
do
newfile=`echo $file | sed 's/black\ sabbath\ //g'`
mv "$file" $newfile
done
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:58 PM.


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