LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash scripting (dynamic files) (http://www.linuxquestions.org/questions/linux-general-1/bash-scripting-dynamic-files-836303/)

mainstream 10-05-2010 08:37 AM

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 :newbie:

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 :D

Thanks & regards,

Mainstream

kurumi 10-05-2010 09:16 AM

Code:

ruby -e 'Dir["*.mp3"].each{|x| File.rename(x, x.sub(/^.[^-]*-/,""))}'

mainstream 10-05-2010 09:42 AM

That worked for the first problem thanks :)

Any idea how i can remove the (%%% bpm)?

kurumi 10-05-2010 10:05 AM

Code:

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

mainstream 10-05-2010 10:13 AM

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


kurumi 10-05-2010 10:20 AM

Code:

ruby -e 'Dir["*.mp3"].each {|x| puts x.sub(/^[0-9]+-/,"").gsub(/\s*\(.*?\)\s*/,"" )  }'

mainstream 10-05-2010 01:05 PM

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

Thanks for you help though!

kurumi 10-07-2010 02:25 AM

Look at post #4 to see how to rename. Please try yourself instead of waiting for it.

X.Cyclop 10-07-2010 09:01 AM

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

;)

ghostdog74 10-07-2010 09:19 AM

Quote:

Originally Posted by X.Cyclop (Post 4120458)
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?

X.Cyclop 10-10-2010 06:26 PM

Quote:

Originally Posted by ghostdog74 (Post 4120472)
really?

:hattip:

mainstream 11-02-2010 11:50 AM

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... :)


All times are GMT -5. The time now is 12:19 PM.