Advanced string replace in Filenames
Hi Guys,
First post. Have to at least start out by saying I've been a long time reader of these forums, and have had many questions answered by the fine community that hangs out here. So before even getting to my question, thank you. Moving right along, I have a folder of MP3 files containing various Movie sound tracks and scores. I'm using Audio Tag Tool to tag all the files at once with an "Artist" of "Soundtrack", and to inherit the "Title" tag from the file name. After that, I will rename all the files (Using Audio Tag Tool -- awesome program, btw) with the format "<Artist> - <Title>.mp3" The problem, is many of my files already contain the string "Soundtrack", which would be redundant. I happen to be a perfectionist, so I'm unable to ignore it and move on. Hence my question to you fine folk: I want to delete all instances of "soundtrack" (-i case irrelevant) in the filenames before I go through the above steps. But, its not quite that simple. This is a sample of some of the file names: Code:
soundtrack - Yanni & Enya - Dances With Wolves.mp3 If I simply renamed all files using sed with s/[sS]oundtrack//g, the files as above wouldn't be "neat". I would end up with: Code:
- Yanni & Enya - Dances With Wolves.mp3 I'm hoping to avoid double spaces, and space beginnings, etc, to ensure general readability. Hence the "advanced" string replacement. I was trying to construct a method to delete "[sS]oundtrack" including any characters directly in front or before from the set: ()- :SPACE: But I'm afraid this exceeds my linux knowledge. Is anyone able to help? I will post the list of file names in the next post so you have data to work with. Thank you in advanced. |
Data Sample
Code:
eddie@xInfinity$ ls | grep -i "soundtrack" |
Well I got close but the issue is now that you have some dashes sitting against some titles (although I notice elsewhere that this is already the case) and that
some lines have the word on its own inside brackets which now remain but are empty?? I have put in a fix to get rid of the last but again it is not as nice as there is now no space: Code:
sed -r -e 's/^[sS]oundtrack[s]?[^a-zA-Z]*//' -e 's/[ (]*[Ss]oundtrack[) ]*//' file |
The data (the file names) is not structured enough for you to be able to do what you want. For example,"Desperado - The Soundtrack - 01 - Los Lobos & Antonio Banderas - Cancion Del Mariachi.mp3" would become "Desperado - The - 01 - Los Lobos & Antonio Banderas - Cancion Del Mariachi.mp3"
|
All times are GMT -5. The time now is 11:54 AM. |