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 1Le4xm-0001si-DT for garchives@archives.gentoo.org; Mon, 02 Mar 2009 10:01:30 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3EE38E0369; Mon, 2 Mar 2009 10:01:29 +0000 (UTC) Received: from duke.wrkhors.com (p70-63.acedsl.com [66.114.70.63]) by pigeon.gentoo.org (Postfix) with ESMTP id 1914CE0369 for ; Mon, 2 Mar 2009 10:01:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by duke.wrkhors.com (Postfix) with ESMTP id E44DF115B04F for ; Mon, 2 Mar 2009 05:01:24 -0500 (EST) Message-ID: <49ABAE74.3000902@wrkhors.com> Date: Mon, 02 Mar 2009 05:01:24 -0500 From: Steven Lembark Organization: Workhorse Computing User-Agent: Thunderbird 2.0.0.19 (X11/20090102) 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 To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] Grep question References: <5602B0BD6D59AE4791BE83104940118D7B1B328A@excprdmbxw002.optus.com.au> In-Reply-To: <5602B0BD6D59AE4791BE83104940118D7B1B328A@excprdmbxw002.optus.com.au> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Archives-Salt: 69d2beee-be93-413f-bba0-bf69536dbb51 X-Archives-Hash: 69a2f69861783d3be3511eabdffdecbe Adam Carter wrote: > 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. Perl will handle this easily enough for you. Assuming you want to print string1 and string2: perl -n -e 'print if /string1/ ../string2/'; The '..' notation behaves sort of like a triac (flip-flop?): it is false until the first test is true and true until the second passes, at which point it stays false again. for 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 $ perl -n -e 'print if /foo/ .. /bar/'; foo asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf bar -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lembark@wrkhors.com +1 888 359 3508