Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Is this the Zsh way for doing this?



    Hi all :)

    WARNING: this is one of my long messages, lots of text ahead!

    I have a text file with the following format:

Album title: 'Elemental'	[from Loreena McKennitt]
Track  1: 'Blacksmith'
Track  2: 'She Moved Through The Fair'
Track  3: 'Stolen Child'
Track  4: 'The Lark In The Clear Air '
Track  5: 'Carrighfergus'
Track  6: 'Kellswater'
Track  7: 'Banks Of Claudy'
Track  8: 'Come By The Hills'
Track  9: 'Lullaby'
Track 10: 'This song really doesn't exist...'

    (This album is quite good, BTW)

    The song number 10 is just to show that the special case. I want
to take the information from this file and use it to rename a bunch
of audio files whose names are of the form 'audio_XX.cdr', where 'XX'
is a number between 00 and 99. I do it like that (I use 'print'
instead 'mv' for testing, as well as the separator "-->"):

tail +2 .CDinfo | while read song
do
    print audio_${(l.2..0.)${song##Track ##}%%:*}.cdr \
    "-->" \
    ${song/#(#b)Track #([0-9]##):'(*)'/${(l.2..0.)match[1]}.${match[2]}}.cdr
done

    The 'tail +2' is for getting rid of the 'Album title' line. After
that I build the name of the audio file using 'song', deleting all
except the number from each line of the file (althoug this can be
done using brace expansion, or a counter, etc...). The new name is
build taking the line again, deleting the 'Track ' part. We then take
the number, pad it to two digits with 0's and replacing the name of
the song without the quotes. AFAIK, when pattern matching takes place
at the point of the "'(*)'", it is implicitly anchored to the end of
the string and is the longest match, so the replacement will
substitute a string like "'It's a string'o'sample'" for "It's a
string'o'sample", and not by "It's a string'o" or "s a string",
etc... The paddings are needed since the song number can have one or
two digits and I want numeric sort in the directory listing without
using the 'n' globbing flag.

    The result is a series of 'mv' commands like:

    mv audio_07.cdr 07.The name of the freakin' song.cdr

    What I want to know is if this is a correct way or if I'm missing
something that will be do the same in a much more clever way, and why
I cannot use the (#b) flag before the '/' (together with 'song') or
before the '#' (which indicates that 'Track' must match at the
beginning of the string). BTW, is that '#' necessary or not? Do I
need to specify too the end of the string anchor?

    Thanks a lot in advance and sorry for the long message. At least
the Loreena McKennitt CD is quite good O:))

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



Messages sorted by: Reverse Date, Date, Thread, Author