LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2011, 12:39 PM   #1
dimwit
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
Question 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
Troy Soundtrack - The Temple Of Poseidon.mp3
Tchaikovsky - 1812 Overture (V For Vendetta Soundtrack).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
Troy  - The Temple Of Poseidon.mp3
Tchaikovsky - 1812 Overture (V For Vendetta ).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.
 
Old 06-11-2011, 12:41 PM   #2
dimwit
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Arrow Data Sample

Code:
eddie@xInfinity$ ls | grep -i "soundtrack"
A Beautiful Mind Soundtrack - Main Theme.mp3
Alan Silvestri - Van Helsing Film Score Soundtrack - 04 Journey To Transylvania.mp3
american beauty - Soundtrack_Opening Theme.mp3
American Beauty Soundtrack - Plastic Bag Theme.mp3
American History X - Benedictus (Soundtrack).mp3
Bewitched - Hey Mickey! (Bring It On Soundtrack).mp3
Bruce Almighty Soundtrack - Snap - I've Got the Power.mp3
Casablanca - Original Motion Picture Soundtrack - As Time Goes By -complete vocal-.mp3
Desperado - The Soundtrack - 01 - Los Lobos & Antonio Banderas - Cancion Del Mariachi.mp3
Desperado The Soundtrack_12_Salma Hayek  Quedate Aqui.mp3
Enya - Now We Are Free (gladiator soundtrack).mp3
Fight Club Soundtrack - 06 - The Dust Brothers - Psycho Boy Jack.mp3
Finding Nemo - Original Soundtrack - Nemo Egg (Main Title).mp3
Finding Nemo Soundtrack - Friends Not Food.mp3
Flying Neutrinos (Blast from the Past) - Mr. Zoot Suit - Blast From The Past Soundtrack.mp3
Forrest Gump Soundtrack - Stop Children What's That Sound.mp3
Gladiator - Soundtrack - 03 - The Battle.mp3
Gladiator Soundtrack - 10 - Strength And Honor.mp3
Gladiator Soundtrack - End Theme.mp3
Gone With The Wind (Tara's Theme) - 1939 - Soundtrack.mp3
Green Mile Soundtrack - Coffey On The Mile.mp3
Hans Zimmer - Kyrie For The Magdalene (The Da Vinci Code Soundtrack).mp3
johnny rebel - american history x soundtrack the white man marches on.mp3
John Williams - Movie Soundtracks - Jurassic Park.mp3
John Williams (schindlers list soundtrack) - Theme from Shindlers List.mp3
Kurtlar Vadisi - Irak Soundtracks 2@V@6 - 03 - Altin Hizma.mp3
Mask of Zoro -Soundtrack - Zorro's Theme.mp3
Movie Soundtracks - Disney - Toy Story - You've Got A Friend In Me.MP3
movie soundtracks - Schindler's List Theme (violin solo by Itzhak Perlman).mp3
Movie Soundtrack - V for Vendetta - Evey Reborn.mp3
Movie Soundtrack - V for Vendetta - The Dominoes Fall.mp3
Movie Themes - Troy - Soundtrack  - 3200 years ago.mp3
Nightwish - Troy soundtrack - Tristania.mp3
Oliver Twist Soundtrack - I'd Do Anything.mp3
Original Motion Picture Soundtrack A Beautiful Mind - All Love Can Be Featuring Charlotte Church.mp3
Out of Africa Soundtrack - John Barry - Main Title.mp3
Patti Labelle - Bruce Almighty Soundtrack - Are You Ready for a Miracle.mp3
Robbie Williams - Beyond The Sea (Finding Nemo Soundtrack).mp3
Saving Private Ryan Soundtrack - Omaha Beach (John Williams).mp3
Saw Soundtrack - 2 - Hello Adam.mp3
Saw Soundtrack - Zepp Overature.mp3
Sin City Soundtrack-19-Fluke - Absurd.mp3
Sin City Soundtrack - Cells by The Servant.mp3
Sin City Soundtrack - sin city theme.mp3
Soundtrack - After The Sunset - I Got It ( Kevin Lyttle ).mp3
Soundtrack - Cast Away - Alan Silvestri - (End Credits).mp3
Soundtrack- Cast Away theme(1).mp3
Soundtrack- Cast Away theme.mp3
Soundtrack - Charlie Clouser - Saw Final Theme.mp3
Soundtrack - First Knight - Jerry Goldsmith - 10 - Camelot Lives.mp3
Soundtrack-Gone with the Wind-01-Main Title (Max Steiner).mp3
Soundtrack - Hans Zimmer - The Da Vinci Code - Chevaliers De Sangreal.mp3
Soundtrack - Oliver Twist - Oom Pah Pah(1).mp3
Soundtrack - Road To Perdition - Thomas Newman - 07 - Road To Chicago.mp3
Soundtracks-Dances With Wolves - Movie Theme.mp3
soundtracks- EXORCIST ~ Very Scary Music - Horror Movie and TV Show Themes.mp3
Soundtracks - Jurassic Park - Main Theme.mp3
soundtracks - Saving Private Ryan Theme.mp3
Soundtracks - The Green Mile (Theme).mp3
Soundtrack - The Da Vinci Code (01. Dies Mercurii i Martius).mp3
Soundtrack (The Last Samurai) - Spectres In The Fog.mp3
Soundtrack Theme-First Knight-End Credits (Jerry Goldsmith).mp3
Soundtrack - Theme - The Omen - Jerry Goldsmith - Ave Satani1.mp3
soundtrack - Yanni & Enya - Dances With Wolves.mp3
Tchaikovsky - 1812 Overture (V For Vendetta Soundtrack).mp3
the 13th warrior soundtrack - valhalla viking victory.mp3
The Chronicals of Narnia- Here Comes The King (Instrumental) (soundtrack) (trailer theme for The Chronicles Of Narnia).mp3
The Chronicles of Narnia - Movie Soundtrack - 07 - From Western Woods to Beaversdam.mp3
The Chronicles of Narnia Soundtrack - 13 - Aslan's Theme (The Chronicles Of Narnia).mp3
The Chronicles of Narnia Soundtrack (Orchestral) - 05 - A Narnia Lullaby.mp3
The OC soundtrack-Imogen Heap - Hide and Seek.mp3
Troy Original Soundtrack - 3200 Years Ago.mp3
Troy Soundtrack -  Hector's Death.mp3
TROY soundtrack - James Horner - Theme.mp3
Troy Soundtrack - The Temple Of Poseidon.mp3
Troy Soundtrack - Troy (Trailer Music).mp3
True Lies Soundtrack (Scent of a Woman) Tango - Carlos Gardel - Por Una Cabeza(1).mp3
True Lies Soundtrack (Scent of a Woman) Tango - Carlos Gardel - Por Una Cabeza.mp3
UB40 - Every Breathe You Take - 50 First Dates Soundtrack.mp3
Van Helsing Soundtrack - Transylvanian Horses(1).mp3
V for Vendetta soundtrack - 01 - Remember, Remember.mp3
V For Vendetta Soundtrack - Cat Power - I Found A Reason.mp3
What A Girl Wants Soundtrack - Oliver James - Greatest Story Ever Told.mp3
X-Ray Dog - 02 - Here Comes The King (Instrumental) (soundtrack) (trailer theme for The Chronicles Of Narnia).mp3
Yanni & enya - Dances with wolves soundtrack - Dances with wolves.mp3
 
Old 06-12-2011, 02:36 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
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
 
Old 06-12-2011, 02:42 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] replace string with empty string of dir path ted_chou12 Linux - Newbie 3 04-02-2011 07:43 AM
how do i replace a text string in a file with a random string? (with sed etc) steve51184 Linux - Software 16 09-02-2010 12:05 PM
Using tr to replace strings in a group of filenames Lemmings Linux - Newbie 7 05-21-2008 12:00 PM
How to replace spaces in filenames with underscores rosslaird Linux - Software 4 02-22-2005 02:08 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 02:04 AM


All times are GMT -5. The time now is 10:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration