Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

bash: stripping numeric characters from filenames

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
mugstar
LXF regular


Joined: Mon Apr 11, 2005 1:43 am
Posts: 184
Location: Scotland

PostPosted: Mon Aug 07, 2006 12:13 am    Post subject: bash: stripping numeric characters from filenames Reply with quote

(I just know this will involve regular expressions ... Sad )

I have a collection of mp3's and ogg's, a lot of which take the form 02_name_of_artist_name_of track.ogg. What I want to end up with is a file called name_of_track.ogg.

I know that I can use
Code:
for i in *.ogg; do mv "$i" "${i/_name_of_artist_}"; done
to strip some of the filename out, but I'm messing up when trying to remove the track numbers from the start of more than one file.

Anybody?
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8464
Location: Warrington, UK

PostPosted: Mon Aug 07, 2006 12:32 am    Post subject: Re: bash: stripping numeric characters from filenames Reply with quote

Code:
for i in *.ogg; do mv "$i" "${i/[0-9][0-9]_name_of_artist_}"; done

_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
mugstar
LXF regular


Joined: Mon Apr 11, 2005 1:43 am
Posts: 184
Location: Scotland

PostPosted: Mon Aug 07, 2006 12:45 am    Post subject: RE: Re: bash: stripping numeric characters from filenames Reply with quote

Aargghhh!! Two seperate ones!

Thanks!
Back to top
View user's profile Send private message
emyr42
LXF regular


Joined: Tue Nov 22, 2005 9:16 am
Posts: 147
Location: Cardiff, UK

PostPosted: Mon Aug 07, 2006 12:13 pm    Post subject: RE: Re: bash: stripping numeric characters from filenames Reply with quote

Shouldn't your code be reading from the ogg file's metadata to find the track name?
_________________
OpenSUSE 10.2, WinXPHome
AMD Sempron 2400, 512MB DDR333, Twin 60GB Deathstars
Back to top
View user's profile Send private message Visit poster's website
nordle
LXF regular


Joined: Fri Apr 08, 2005 10:56 pm
Posts: 1500

PostPosted: Tue Aug 08, 2006 10:08 pm    Post subject: RE: Re: bash: stripping numeric characters from filenames Reply with quote

02_name_of_artist_name_of track.ogg

But surely the best you can ever hope for with pattern matching is

name_of_artist_name_of track.ogg

Unless you started with something like:

02_name_of_artist__name_of track.ogg
_________________
I think, therefore I compile
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast