From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19338 invoked from network); 15 Aug 2005 20:18:24 -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 20:18:24 -0000 Received: (qmail 82846 invoked from network); 15 Aug 2005 20:18:09 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Aug 2005 20:18:09 -0000 Received: (qmail 12913 invoked by alias); 15 Aug 2005 20:18:02 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9319 Received: (qmail 12902 invoked from network); 15 Aug 2005 20:18:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Aug 2005 20:18:01 -0000 Received: (qmail 81751 invoked from network); 15 Aug 2005 20:18:01 -0000 Received: from ns9.hostinglmi.net (213.194.149.146) by a.mx.sunsite.dk with SMTP; 15 Aug 2005 20:17:56 -0000 Received: from 212.red-80-35-44.pooles.rima-tde.net ([80.35.44.212] helo=localhost) by ns9.hostinglmi.net with esmtpa (Exim 4.51) id 1E4lPD-0002xN-GH; Mon, 15 Aug 2005 22:18:00 +0200 Date: Mon, 15 Aug 2005 22:21:26 +0200 From: DervishD To: Peter Stephenson Cc: Zsh Users Subject: Re: Replacing sed for zsh portability Message-ID: <20050815202126.GA64@DervishD> Mail-Followup-To: Peter Stephenson , Zsh Users References: <20050815103557.GA1411@DervishD> <2283.1124104964@csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2283.1124104964@csr.com> User-Agent: Mutt/1.4.2.1i Organization: DervishD X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns9.hostinglmi.net X-AntiAbuse: Original Domain - sunsite.dk X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dervishd.net X-Source: X-Source-Args: X-Source-Dir: 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.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Hi Peter :) * Peter Stephenson dixit: > DervishD wrote: > > 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="$( > print -r ${(S)file//$'\n#<='*$'\n#=>'} This prints all the script *except* the lines I want ;) Anyway, can I get rid of the 'S' flag if I know that the delimiter won't appear in the script code? Using the 'read-entire-file' solution, I'm using this expression right now: print -r ${file//(#b)*'#<='(*)'#=>'*/${match//\#/}} Which gives a segmentation fault! It happens even when doing "zsh -f", using 4.2.5 (i686-pc-linux-gnu) This expression below: print -r ${file//(#b)*'#<='(*)'#=>'*/$match} gives me the result but with the hashes before the lines, and uses the '\n' already in the text as separators. A bit prettier, don't know. And this expression works OK: print -r ${${file//(#b)*'#<='(*)'#=>'*/$match}//\#} Don't know why the second substitution works and the first gave a sigsegv. I may do a little research if you want me to. I'm not familiar with the sources, but the fail may be on a memcpy call, at least is there where it fails using gdb without debugging information :(( > 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#=>'} Fortunately the comment won't never be at the start (the GPL disclaimer is the first thing in the script just after the bangpath. > > 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##\#(<=|=>| |)} Yes, read my autoreply about my stupidity when writing the expression. I just missed the second '#'. I noticed when rereading my own message. Only then the single '#' appeared as a beacon. Sorry O:) Thanks for your answer, Peter :) Very good solution. I refrained from reading the entire file into memory although I am pretty sure the scripts are small enough. Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 | http://www.dervishd.net http://www.pleyades.net & http://www.gotesdelluna.net It's my PC and I'll cry if I want to...