You are not logged in.

#1 2009-11-05 20:13:04

flocntl
Member
Registered: 2007-10-02
Posts: 29

sed script help

Hi, I could use your help..

The problem: I've got an m3u playlist with some of my favorite tracks. The files reside in album folders, which follow a naming scheme, but that has changed so I have to update all the references. What I have in mind is to use sed for extracting the mp3 filename, then somehow find the new path to that file and substitute it for the old one. I've managed to crawl this far, but obviously it won't work:

cat ultimate.m3u | sed -e 's/.*\///g' | sed -e 's/\(.*\.mp3')/`find -name \1`/g

please show me some geekism, regards
flo

Offline

#2 2009-11-05 20:32:57

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: sed script help

Could you show us eg. 10 entries from 'ultimate.m3u' ? (I hope there are no spaces in the filenames!!)

Offline

#3 2009-11-05 20:39:42

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: sed script help

yes... more info plz... like "old scheme" and "new scheme". Please specify what they are smile


Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#4 2009-11-05 20:41:17

flocntl
Member
Registered: 2007-10-02
Posts: 29

Re: sed script help

sure. na, no spaces, i despise those tongue

G2/G2-G2010-2003-Bad_MF/01-bad-mf-cosmois.mp3
720_Degrees/720_Degrees-720NU016-Blame-2004/01-blame-desert_planet.mp3
Virus-Various_Artists-VRS009-Life_Story_Vol_1-2001/02-cause_4_concern-peep_show.mp3
1210/1210-1210-006-Crossfire-2003/01-crossfire_-_hideout.mp3
Violence/Violence-Gridlok-2003-VIO006/02-gridlok-aggressor.mp3

the new scheme is more consistent .. mostly, e.a. Artist-CatNo-...

Last edited by flocntl (2009-11-05 20:43:39)

Offline

#5 2009-11-05 20:41:30

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: sed script help

while read old_path; do
  file="$(basename "$old_path")"
  new_path="$(find ~/Music -name "$file")"
  echo $new_path >> ./ultimate_new.m3u
done < ./ultimate.m3u

untested, should work with spaces.

Offline

#6 2009-11-05 20:46:11

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: sed script help

@brisbin33
*lol* you just pulled the rug from under my feet - that was more or less exactly what I would have suggested ... (there are always more ways than one to skin a cat, and personally I abhor these sed escape-sequences ...)

Offline

#7 2009-11-05 21:33:10

flocntl
Member
Registered: 2007-10-02
Posts: 29

Re: sed script help

hmm, thanks brisbin33, but it seems that new_path is always empty. I guess "$file" won't evaluate in the find command?

Offline

#8 2009-11-05 23:06:40

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: sed script help

cannot reproduce...

//blue/0/~ cat ./test.m3u 
G2/G2-G2010-2003-Bad_MF/01-bad-mf-cosmois.mp3
720_Degrees/720_Degrees-720NU016-Blame-2004/01-blame-desert_planet.mp3
Virus-Various_Artists-VRS009-Life_Story_Vol_1-2001/02-cause_4_concern-peep_show.mp3
1210/1210-1210-006-Crossfire-2003/01-crossfire_-_hideout.mp3
Violence/Violence-Gridlok-2003-VIO006/02-gridlok-aggressor.mp3
//blue/0/~ while read old_path; do 
// file=$(basename $old_path)
// echo file is $file
// echo "i would be finding ./ -name '$file' right now..."
// done < ./test.m3u 
file is 01-bad-mf-cosmois.mp3
i would be finding ./ -name '01-bad-mf-cosmois.mp3' right now...
file is 01-blame-desert_planet.mp3
i would be finding ./ -name '01-blame-desert_planet.mp3' right now...
file is 02-cause_4_concern-peep_show.mp3
i would be finding ./ -name '02-cause_4_concern-peep_show.mp3' right now...
file is 01-crossfire_-_hideout.mp3
i would be finding ./ -name '01-crossfire_-_hideout.mp3' right now...
file is 02-gridlok-aggressor.mp3
i would be finding ./ -name '02-gridlok-aggressor.mp3' right now...

seems to be working here.  perhaps your not looking in the right directory with your find command? ~/Music was just my example.

Offline

Board footer

Powered by FluxBB