[Gllug] Extracting substrings in bash script

Ziya Suzen ziya at suzen.net
Tue Nov 6 21:58:04 UTC 2007


On 11/6/07, Dylan <dylan at dylan.me.uk> wrote:
[..]
> dylan at hal:~> tagmp3 show test.mp3
> 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:
[..]
> So, what are the many and various possibilities for extracting the Artist,
> Title, Album and Track from that string?

#!/bin/bash

IFS="
"
for line in $(tagmp3 show test.mp3)
do
    echo field ${line:3:6}
    echo value ${line:12}
    echo
done

Check out 'Parameter Expansion' in man bash. If that's not enough you
might want to use sed/awk or their evil twin perl.

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




More information about the GLLUG mailing list