![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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 |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|