From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1LeK5r-0000d3-5X for garchives@archives.gentoo.org; Tue, 03 Mar 2009 02:10:51 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 56A75E0349; Tue, 3 Mar 2009 02:10:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2DC54E0349 for ; Tue, 3 Mar 2009 02:10:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id CD49664564 for ; Tue, 3 Mar 2009 02:10:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at gentoo.org X-Spam-Score: -3.042 X-Spam-Level: X-Spam-Status: No, score=-3.042 required=5.5 tests=[AWL=-0.443, BAYES_00=-2.599] Received: from smtp.gentoo.org ([127.0.0.1]) by localhost (smtp.gentoo.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cAEF9ujHTMCX for ; Tue, 3 Mar 2009 02:10:40 +0000 (UTC) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id B3E5B64528 for ; Tue, 3 Mar 2009 02:10:40 +0000 (UTC) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LeK5X-0004nw-JO for gentoo-user@gentoo.org; Tue, 03 Mar 2009 02:10:31 +0000 Received: from c-98-215-178-6.hsd1.in.comcast.net ([98.215.178.6]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Mar 2009 02:10:31 +0000 Received: from reader by c-98-215-178-6.hsd1.in.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Mar 2009 02:10:31 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: gentoo-user@lists.gentoo.org From: Harry Putnam Subject: [gentoo-user] Re: Grep question Date: Mon, 02 Mar 2009 20:10:16 -0600 Organization: Still searching... Message-ID: <87ab832w6v.fsf@newsguy.com> References: <5602B0BD6D59AE4791BE83104940118D7B1B328A@excprdmbxw002.optus.com.au> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-98-215-178-6.hsd1.in.comcast.net User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux) Cancel-Lock: sha1:nAM2SDUCVPbD+pxVn2o/VXIybTI= Sender: news X-Archives-Salt: 878a0406-fd9c-4cb6-aeac-1b76fc9ca395 X-Archives-Hash: e0d2e53d18f3d60718e282a66f327e76 James writes: > Adam Carter optus.com.au> writes: > > >> I need to select all >> the lines between string1 and string2 in a file. String1 exists on > an entire >> line by itself and string2 will be at the start of a line. What's > the syntax? I >> cant use -A as there is a variable number of lines. > > AWK > > is my vote. Old, *SIMPLE* and used by most other packages when > pattern matching is involved. Often AWK and SED go together..... As > do Perl and AWK Yup and using Steves' example: $ cat a abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd foo <-- /foo/ true here asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf bar <-- /bar/ true here fdsa fdsa fdsa cat a | awk '/^foo/{FLAG=1}\ FLAG{print} \ /^bar/{FLAG=""}' foo asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf bar