From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2499 invoked from network); 15 Aug 2005 11:23:05 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Aug 2005 11:23:05 -0000 Received: (qmail 75964 invoked from network); 15 Aug 2005 11:22:59 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Aug 2005 11:22:59 -0000 Received: (qmail 23450 invoked by alias); 15 Aug 2005 11:22:52 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9317 Received: (qmail 23441 invoked from network); 15 Aug 2005 11:22:52 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Aug 2005 11:22:52 -0000 Received: (qmail 74897 invoked from network); 15 Aug 2005 11:22:52 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 15 Aug 2005 11:22:46 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Mon, 15 Aug 2005 12:20:34 +0100 Received: from csr.com ([10.102.144.127]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 15 Aug 2005 12:22:44 +0100 To: Zsh Users Subject: Re: Replacing sed for zsh portability In-reply-to: <20050815103557.GA1411@DervishD> References: <20050815103557.GA1411@DervishD> Comments: In-reply-to DervishD message dated "Mon, 15 Aug 2005 12:35:57 +0200." Date: Mon, 15 Aug 2005 12:22:44 +0100 Message-ID: <2283.1124104964@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 15 Aug 2005 11:22:44.0546 (UTC) FILETIME=[A843AA20:01C5A18B] X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 DervishD wrote: > #<= > # This is an example of documentation > # Here are more lines > # > # Yet even more lines here > ... > #=> > > Since I cannot use sed for the entire work unless I complicate > the script (doing multiple substitutions and the like), I want to get > rid of the current script and doing all the job in ZSH. It doesn't > matter if it is very slow, speed here is not an issue. > > Can this be done in zsh easily or the only way is to use a while > loop to ignore lines before the delimiter and another to process the > documentation itself? A while loop is the obvious way. You can read in the entire file (file="$('} although the following is better since it takes account of the fact that a comment may be at the start: print -r ${(S)file//($'\n'|(#s))\#\<\=*$'\n#=>'} This requires extended_glob. > Another question, related to this. It seems that the X|Y glob > operator doesn't work left-to-right, but shortest-first. If I do > this: > > print ${line#\#(<=|=>| |)} > > then the 'nothing' at the end is used as the match, and the > delimiters are not matched. You're missing the fact that your substitution is of the form ${line#...}. This is explicitly documented to remove the shortest matching chunk at the head of the line. Try adding another "#": print ${line##\#(<=|=>| |)} -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************