LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 10-05-2010, 08:37 AM   #1
mainstream
Member
 
Registered: Oct 2010
Location: localhost
Distribution: Ubuntu / Linux Mint
Posts: 61

Rep: Reputation: 0
Bash scripting (dynamic files)


Hello everybody,

I've been surfing and searching the net quit a while now to make my own script, but i haven't been really succesfull ever since

I want to make a script which can remove strings from my mp3 collection (file names).

for example:

Code:
101-bob_sinclar_feat_sean_paul-tik_tok_(radio_edit).mp3 --> bob_sinclar_feat_sean_paul-tik_tok_(radio_edit).mp3
10-Young Jeezy-Lose My Mind (78 Bpm) (Repack).mp3 --> young_jeezy-lose_my_mind.mp3
now the problem is how can i remove the strings like:
101 & 10 (dynamic)
(%%% Bpm) (dynamic)
(Repack) (static)

Any help is greatly appreciated

Thanks & regards,

Mainstream

Last edited by mainstream; 10-05-2010 at 08:51 AM.
 
Old 10-05-2010, 09:16 AM   #2
kurumi
Member
 
Registered: Apr 2010
Posts: 223

Rep: Reputation: 45
Code:
ruby -e 'Dir["*.mp3"].each{|x| File.rename(x, x.sub(/^.[^-]*-/,""))}'
 
Old 10-05-2010, 09:42 AM   #3
mainstream
Member
 
Registered: Oct 2010
Location: localhost
Distribution: Ubuntu / Linux Mint
Posts: 61

Original Poster
Rep: Reputation: 0
That worked for the first problem thanks

Any idea how i can remove the (%%% bpm)?
 
Old 10-05-2010, 10:05 AM   #4
kurumi
Member
 
Registered: Apr 2010
Posts: 223

Rep: Reputation: 45
Code:
ruby -e 'Dir["*.mp3"].each {|x| File.rename(x,x.sub(/^.[^-]*-/,"").gsub(/\s*\(.*?\)\s*/,""))}'
 
Old 10-05-2010, 10:13 AM   #5
mainstream
Member
 
Registered: Oct 2010
Location: localhost
Distribution: Ubuntu / Linux Mint
Posts: 61

Original Poster
Rep: Reputation: 0
Hmm tried that, but this removes everything except the title and screws up some files:

1st:
Code:
Swedish House Mafia vs Tinie Tempah-Miami 2 Ibiza (Extended Vocal Mix Explicit).mp3
Swedish House Mafia vs Tinie Tempah-Miami 2 Ibiza (Radio Edit Explicit).mp3
Ne-Yo-Beautiful Monster (128 Bpm) (Repack).mp3
2nd:
Code:
Miami 2 Ibiza.mp3
mp3
Yo-Beautiful Monster.mp3
 
Old 10-05-2010, 10:20 AM   #6
kurumi
Member
 
Registered: Apr 2010
Posts: 223

Rep: Reputation: 45
Code:
ruby -e 'Dir["*.mp3"].each {|x| puts x.sub(/^[0-9]+-/,"").gsub(/\s*\(.*?\)\s*/,"" )  }'
 
Old 10-05-2010, 01:05 PM   #7
mainstream
Member
 
Registered: Oct 2010
Location: localhost
Distribution: Ubuntu / Linux Mint
Posts: 61

Original Poster
Rep: Reputation: 0
Hmm ok.
But this only echo's the filenames, it doesn't really change anything :-(

Thanks for you help though!
 
Old 10-07-2010, 02:25 AM   #8
kurumi
Member
 
Registered: Apr 2010
Posts: 223

Rep: Reputation: 45
Look at post #4 to see how to rename. Please try yourself instead of waiting for it.
 
Old 10-07-2010, 09:01 AM   #9
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
Since what you want to erase is at the beginning and in the end..:
Code:
mv 131-MySong.mp3 $(ls *.txt | cut -c3-50)
cut -cStaringPoint-EndingPoint


Last edited by X.Cyclop; 10-07-2010 at 09:02 AM.
 
Old 10-07-2010, 09:19 AM   #10
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by X.Cyclop View Post
Since what you want to erase is at the beginning and in the end..:
Code:
mv 131-MySong.mp3 $(ls *.txt | cut -c3-50)
cut -cStaringPoint-EndingPoint

really?
 
Old 10-10-2010, 06:26 PM   #11
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
Quote:
Originally Posted by ghostdog74 View Post
really?
 
Old 11-02-2010, 11:50 AM   #12
mainstream
Member
 
Registered: Oct 2010
Location: localhost
Distribution: Ubuntu / Linux Mint
Posts: 61

Original Poster
Rep: Reputation: 0
Sorry for my late response as i had family problems.
Thanks for all comments, it's finally working :-D

Is there btw a way to check if a file start with numeric content? and only remove the first characters
i.e. 00-hello-asd.mp3 --> hello-asd.mp3
202-hadsas-asdas.mp3 --> hadsas-asdas.mp3



if [[ "$i" == "$new" ]]
then
ruby -e 'Dir["*.mp3"].each {|x| File.rename(x,x.sub(/^.[^-]*-/,"").gsub(/\s*\(.*?\)\s*/,""))}'
else

lol...

Last edited by mainstream; 11-02-2010 at 12:06 PM.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Going through files in a directory, bash scripting Pewgs Linux - Newbie 10 04-12-2010 12:34 AM
Bash Scripting - Configuration files piercey Programming 8 10-17-2008 11:41 AM
Bash Shell Scripting Dynamic Variable naming question ZuG Programming 2 02-07-2007 03:39 PM
bash scripting - editing files brian0918 Linux - Newbie 2 07-01-2003 03:27 PM
bash scripting - editing files brian0918 Programming 1 06-30-2003 07:16 PM


All times are GMT -5. The time now is 09:25 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration