[Gllug] Extracting substrings in bash script

Tethys sta296 at astradyne.co.uk
Tue Nov 6 22:17:09 UTC 2007


--------

Dylan writes:

>t=`tagmp3 show test.mp3`
>echo $t
>
>I get:
>
>Test.mp3 Artist : The Streets Title : It Was Supposed to Be So Easy Album : A 
>Grand Don't Come for Free Track : 1 Year : 2004 Genre : Other Comment:

Yes, because you didn't quote $t, so the newlines weren't preserved.
Try with:

	echo "$t"

and you should see what you expect.

>So, what are the many and various possibilities for extracting the Artist, 
>Title, Album and Track from that string?

	for i in Title Album Track Year Genre Comment
	do
		re="/$i/s/.*: *//;t;d"
		echo -n "Component $i: "
		echo "$t" | sed "$re"
	done

Tet
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list