From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21096 invoked from network); 2 Sep 2006 07:16:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 2 Sep 2006 07:16:56 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 52069 invoked from network); 2 Sep 2006 07:16:50 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 2 Sep 2006 07:16:50 -0000 Received: (qmail 20539 invoked by alias); 2 Sep 2006 07:16:39 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10656 Received: (qmail 20529 invoked from network); 2 Sep 2006 07:16:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 2 Sep 2006 07:16:38 -0000 Received: (qmail 50341 invoked from network); 2 Sep 2006 07:16:38 -0000 Received: from ms-2.rz.rwth-aachen.de (HELO ms-dienst.rz.rwth-aachen.de) (134.130.3.131) by a.mx.sunsite.dk with SMTP; 2 Sep 2006 07:16:37 -0000 Received: from r220-1 (r220-1.rz.RWTH-Aachen.DE [134.130.3.31]) by ms-dienst.rz.rwth-aachen.de (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0J4X005626DTIG@ms-dienst.rz.rwth-aachen.de> for zsh-users@sunsite.dk; Fri, 01 Sep 2006 17:15:29 +0200 (MEST) Received: from relay.rwth-aachen.de ([134.130.3.1]) by r220-1 (MailMonitor for SMTP v1.2.2 ) ; Fri, 01 Sep 2006 17:15:28 +0200 (MEST) Received: from fsst.voodoo.lan (i577BD293.versanet.de [87.123.210.147]) by relay.rwth-aachen.de (8.13.7/8.13.3/1) with ESMTP id k81FFScx024030 for ; Fri, 01 Sep 2006 17:15:28 +0200 (MEST) Received: from hawk by fsst.voodoo.lan with local (Exim 4.63) (envelope-from ) id 1GJAjl-0005QG-Je for zsh-users@sunsite.dk; Fri, 01 Sep 2006 17:15:17 +0200 Date: Fri, 01 Sep 2006 17:15:17 +0200 From: Frank Terbeck Subject: Re: I want to list the NEXT line after a string appears in a list of files In-reply-to: To: zsh-users@sunsite.dk Mail-followup-to: zsh-users@sunsite.dk Message-id: <20060901151517.GC18634@fsst.voodoo.lan> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT Content-disposition: inline Operating-System: Linux 2.6.16.16 i686 User-Agent: Mutt/1.5.13 (2006-08-11) References: zzapper : > I want to list the NEXT line after a string appears in a list of files > > eg > > egrep "Anecdote" m??.txt (But display next line) > > I guess Sed/Awk would do this, I would probably use Perl. > > Suggestions pls [snip] zsh% cat test0.txt These are lines, I do not care about. but please display this line. zsh% cat test1.txt and please, oh please: display this line, too. not this one zsh% function my_grep () { local integer found=0 while read line ; do (( found == 1 )) && print ${line} && return (( found == 0 )) && [[ ${line} = *${1}* ]] && found=1 done < ${2} } zsh% for file in test*.txt ; do my_grep 'please' $file ; done display this line. display this line, too. [snap] Regards, Frank