From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11330 invoked from network); 1 Sep 2006 15:29:33 -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 15:29:33 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 79092 invoked from network); 1 Sep 2006 15:29:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Sep 2006 15:29:28 -0000 Received: (qmail 1744 invoked by alias); 1 Sep 2006 15:29:17 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10652 Received: (qmail 1731 invoked from network); 1 Sep 2006 15:29:16 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Sep 2006 15:29:16 -0000 Received: (qmail 77342 invoked from network); 1 Sep 2006 15:29:16 -0000 Received: from ka.cs.utk.edu (160.36.56.221) by a.mx.sunsite.dk with SMTP; 1 Sep 2006 15:29:15 -0000 Received: from localhost (localhost [127.0.0.1]) by ka.cs.utk.edu (Postfix) with ESMTP id 4EC052F1FE; Fri, 1 Sep 2006 11:29:56 -0400 (EDT) X-Virus-Scanned: by amavisd-new with ClamAV and SpamAssasin at cs.utk.edu Received: from ka.cs.utk.edu ([127.0.0.1]) by localhost (ka.cs.utk.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eZCDgr3weJ+s; Fri, 1 Sep 2006 11:29:53 -0400 (EDT) Received: from cetus30.cs.utk.edu (cetus30.cs.utk.edu [160.36.56.112]) by ka.cs.utk.edu (Postfix) with ESMTP id 8A9432F1ED; Fri, 1 Sep 2006 11:29:39 -0400 (EDT) Received: by cetus30.cs.utk.edu (Postfix, from userid 10605) id 92F5113B5E; Fri, 1 Sep 2006 11:28:56 -0400 (EDT) Date: Fri, 1 Sep 2006 11:28:56 -0400 From: Chris Johnson To: zzapper Cc: zsh-users@sunsite.dk Subject: Re: I want to list the NEXT line after a string appears in a list of files Message-ID: <20060901152856.GA3545@cetus30.cs.utk.edu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i zzapper sent me the following 0.3K: > 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 cat file | awk 'BEGIN {print_next = 0;} {if (print_next) {print $0; print_next = 0;}} /PATTERN/ {print_next = 1;}' Here's an awk solution. If your line matches PATTERN, it sets a flag. When the next record is read, the flag is evaluated. If set, the record is printed. This solution allows for a single line to both be printed and match. -- Chris Johnson cjohnson@cs.utk.edu http://www.cs.utk.edu/~cjohnson