From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15297 invoked from network); 1 Sep 2006 16:52:35 -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=AWL,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; 1 Sep 2006 16:52:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 15379 invoked from network); 1 Sep 2006 16:52:26 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Sep 2006 16:52:26 -0000 Received: (qmail 27843 invoked by alias); 1 Sep 2006 16:52:19 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10655 Received: (qmail 27833 invoked from network); 1 Sep 2006 16:52:19 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Sep 2006 16:52:19 -0000 Received: (qmail 14486 invoked from network); 1 Sep 2006 16:52:19 -0000 Received: from mailhost.u-strasbg.fr (130.79.200.151) by a.mx.sunsite.dk with SMTP; 1 Sep 2006 16:52:18 -0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.13.6/jtpda-5.5pre1) with ESMTP id k81GqHJA021045 for ; Fri, 1 Sep 2006 18:52:17 +0200 (CEST) Received: from xpeerience.u-strasbg.fr (xpeerience.u-strasbg.fr [130.79.188.35]) by baal.u-strasbg.fr (8.13.7/jtpda-5.5pre1) with ESMTP id k81GqHQC064716 for ; Fri, 1 Sep 2006 18:52:17 +0200 (CEST) Received: by xpeerience.u-strasbg.fr (Postfix, from userid 1000) id 058A2D2C26; Fri, 1 Sep 2006 18:52:36 +0200 (CEST) Date: Fri, 1 Sep 2006 18:52:36 +0200 From: Marc Chantreux To: zsh-users@sunsite.dk Subject: Re: I want to list the NEXT line after a string appears in a list of files Message-ID: <20060901165235.GA2122@ulpmm.u-strasbg.fr> Mail-Followup-To: zsh-users@sunsite.dk References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.13 (2006-08-11) Content-Transfer-Encoding: quoted-printable X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (mailhost.u-strasbg.fr [IPv6:2001:660:2402::151]); Fri, 01 Sep 2006 18:52:17 +0200 (CEST) X-Virus-Scanned: ClamAV 0.88.4/1784/Fri Sep 1 14:00:05 2006 on mr1.u-strasbg.fr X-Virus-Status: Clean le 01/09/2006, zzapper nous =E9crivait : > Hi > I want to list the NEXT line after a string appears in a list of files choose your destiny :=20 - little files : zsh=20 - medium : sed/awk (1) - big : perl (1) every one but the GNU one which is damn slow !=20 echo ' find a=20 find a=20 find a=20 find a=20 pattern x and print it ' > file print sed: sed -n '/pattern/ { # if pattern found n # read next line p # print the current line }' < file print wich can be written as: sed -n '/pattern/{n;p}' < file print perl: perl -lne 'print $_=3D<> if /pattern/' file print awk: awk '/pattern/ { getline ; print }' file print zsh ----------------- print first occurence : # 1. store the content of file, line by line content=3D( ${(f)"$( < file)"} ) # find a line containing your pattern=20 # > ${content[(i)*pattern*]} # and print the next one print ${content[${content[(i)*pattern*]} + 1]} print all occurences : while {read} { [[ $REPLY =3D=3D *pattern* ]] && read line && print $line } < file regards --=20 t=E9l=E9phone : 03.90.24.00.19 courriel : marc.chantreux@ulpmm.u-strasbg.fr ---------------------------------------