From owner-freebsd-questions@FreeBSD.ORG Sun Apr 15 16:52:52 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 933FA16A403 for ; Sun, 15 Apr 2007 16:52:52 +0000 (UTC) (envelope-from parv@pair.com) Received: from mta9.adelphia.net (mta9.adelphia.net [68.168.78.199]) by mx1.freebsd.org (Postfix) with ESMTP id 50BA013C4AE for ; Sun, 15 Apr 2007 16:52:52 +0000 (UTC) (envelope-from parv@pair.com) Received: from default.chvlva.adelphia.net ([24.126.17.68]) by mta9.adelphia.net (InterMail vM.6.01.05.02 201-2131-123-102-20050715) with ESMTP id <20070415165251.DQJU14403.mta9.adelphia.net@default.chvlva.adelphia.net>; Sun, 15 Apr 2007 12:52:51 -0400 Received: by default.chvlva.adelphia.net (Postfix, from userid 1000) id 3715DB60A; Sun, 15 Apr 2007 12:53:09 -0400 (EDT) Date: Sun, 15 Apr 2007 12:53:09 -0400 From: Parv To: Zhang Weiwu Message-ID: <20070415165309.GA1175@holestein.holy.cow> Mail-Followup-To: Zhang Weiwu , f-q References: <1176603461.20274.12.camel@joe.realss.com> <20070415054023.GA6596@holestein.holy.cow> <1176625617.22011.16.camel@joe.realss.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1176625617.22011.16.camel@joe.realss.com> Cc: f-q Subject: Re: [OT] can sed handle this situation? (might require variable) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: f-q List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Apr 2007 16:52:52 -0000 in message <1176625617.22011.16.camel@joe.realss.com>, wrote Zhang Weiwu thusly... > > On Sun, 2007-04-15 at 01:40 -0400, Parv wrote: > > in message <1176603461.20274.12.camel@joe.realss.com>, > > wrote Zhang Weiwu thusly... ... > > > I've got a situation that looks like require using variable > > > and not possible to process with sed. But I am not sure. Can > > > someone suggest me if this task is out of scope of sed? > > > > Try some variation of what Garret suggested if sed is the > > requirement and skip rest of the message. > > Thank you very much for all of you providing insights. I have not > yet tried all possibilities in sed but I have just discovered it's > relatively easy to handle this task in awk with this script: > > /^$/ { print "createTimestamp:", timeStamp; timeStamp = ""; } This prints a "createTimestamp:" line on its own block for every 2 consecutive empty lines (in context of the whole program). > /^ahkCreateTimeStamp:/ { timeStamp = $2;} > /^createTimestamp:/ { if (timeStamp == "") timeStamp = $2; } > > $0 !~ /^ahkCreateTimeStamp:/ && $0 !~ /^createTimestamp:/ { > print; > } Interesting, your description of the solution (sadly not in the quoted reply) allowed for "createTimestamp" move to "ahkCreateTimeStamp" line, but implementation above keeps the "createTimestamp" at its place. So I suppose order does not matter(?). - Parv --