From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4911 invoked from network); 25 Mar 2004 22:35:27 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 25 Mar 2004 22:35:27 -0000 Received: (qmail 24694 invoked by alias); 25 Mar 2004 22:34:57 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7271 Received: (qmail 24676 invoked from network); 25 Mar 2004 22:34:56 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 25 Mar 2004 22:34:56 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 25 Mar 2004 22:34:56 -0000 Received: (qmail 29815 invoked from network); 25 Mar 2004 22:34:56 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 25 Mar 2004 22:34:54 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i2PMYqd13909 for ; Thu, 25 Mar 2004 23:34:52 +0100 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1B6dRk-0003S2-00>; Thu, 25 Mar 2004 23:35:32 +0100 Date: Thu, 25 Mar 2004 23:32:28 +0100 From: DervishD To: Zsh Users Subject: Is this the Zsh way for doing this? Message-ID: <20040325223228.GA13221@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4.2.1i Organization: Pleyades Resent-From: DervishD Resent-Date: Thu, 25 Mar 2004 23:35:32 +0100 Resent-To: Zsh Users Resent-Message-Id: X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 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/