bash: stripping numeric characters from filenames

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

bash: stripping numeric characters from filenames

Postby mugstar » Sun Aug 06, 2006 11:13 pm

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

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: Select all
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?
mugstar
LXF regular
 
Posts: 184
Joined: Mon Apr 11, 2005 12:43 am
Location: Scotland

Re: bash: stripping numeric characters from filenames

Postby nelz » Sun Aug 06, 2006 11:32 pm

Code: Select all
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)
User avatar
nelz
Site admin
 
Posts: 8468
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: Re: bash: stripping numeric characters from filenames

Postby mugstar » Sun Aug 06, 2006 11:45 pm

Aargghhh!! Two seperate ones!

Thanks!
mugstar
LXF regular
 
Posts: 184
Joined: Mon Apr 11, 2005 12:43 am
Location: Scotland

RE: Re: bash: stripping numeric characters from filenames

Postby emyr42 » Mon Aug 07, 2006 11:13 am

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
User avatar
emyr42
LXF regular
 
Posts: 147
Joined: Tue Nov 22, 2005 9:16 am
Location: Cardiff, UK

RE: Re: bash: stripping numeric characters from filenames

Postby nordle » Tue Aug 08, 2006 9:08 pm

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
User avatar
nordle
LXF regular
 
Posts: 1500
Joined: Fri Apr 08, 2005 9:56 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron