zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Is this the Zsh way for doing this?
Date: Thu, 25 Mar 2004 23:32:28 +0100	[thread overview]
Message-ID: <20040325223228.GA13221@DervishD> (raw)

    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/


             reply	other threads:[~2004-03-25 22:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-25 22:32 DervishD [this message]
2004-03-28  0:55 ` Bart Schaefer
2004-03-28  1:03   ` Bart Schaefer
2004-03-28 20:07     ` DervishD
2004-03-28 21:00       ` Bart Schaefer
2004-03-29 14:08         ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040325223228.GA13221@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).