The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 10:16 AM
how to rename multiple files with a single command tayyabq8 Shell Programming and Scripting 5 03-18-2008 04:04 PM
How to rename multiple files with a common suffix er_ashu UNIX for Dummies Questions & Answers 1 09-28-2007 10:52 AM
Rename part of multiple files sajjad02 Shell Programming and Scripting 4 02-22-2005 01:30 PM
Rename Multiple Files molonede UNIX for Dummies Questions & Answers 1 11-14-2000 12:40 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 06-10-2002
luiz_fer10 luiz_fer10 is offline
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
  #2 (permalink)  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
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 (permalink)  
Old 06-10-2002
luiz_fer10 luiz_fer10 is offline
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 (permalink)  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
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 (permalink)  
Old 06-10-2002
luiz_fer10 luiz_fer10 is offline
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 (permalink)  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
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 (permalink)  
Old 06-10-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
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
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 07:13 AM.


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