Click to See Complete Forum and Search --> : Information extraction


VoiDeR
06-04-2005, 01:18 AM
Im trying to write a script (perl or bash doesnt matter) that will get the file location from xmms-info. Heres what i have so far

cat /tmp/xmms-info_voider.0 | grep File: | sed -e 's/.* //'
and i get the output
/mnt/storage/music/ARTIST/ALBUM/SONG.mp3

I need to get it down to /mnt/storage/music/ARTIST/ALBUM/
Im sure that all i need to do is pipe the output from the first command through sed again but im not very good with the sed command. I tried using perl but im still learning it.

VoiDeR

bwkaz
06-04-2005, 09:14 AM
The dirname command comes to mind (and also getting rid of a Useless Use of Cat :p):

file="$(grep File: /tmp/xmms-info_voider.0 | sed -e 's/.* //')"

dir="$(dirname "$file")" All the quotes are for the case where your filename (or a directory in the path) has spaces or tabs in it. Newlines will screw up grep and sed already, so there's not much point in handling that (although the quotes would).

VoiDeR
06-04-2005, 09:49 AM
Thanks bwkaz that works great. If you dont mind me asking why does everyone not like using the cat command. I love the cat command and use it all the time. Should i stop.

VoiDeR

bwkaz
06-04-2005, 04:57 PM
It's not that I don't like cat; it's that you're wasting a process for no good reason. ;)

Also see:

http://www.ruhr.de/home/smallo/award.html