From owner-freebsd-questions@FreeBSD.ORG Mon Apr 16 00:40:57 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 4CAD916A401 for ; Mon, 16 Apr 2007 00:40:57 +0000 (UTC) (envelope-from zhangweiwu@realss.com) Received: from bossdog.realss.com (bossdog.realss.com [211.157.108.128]) by mx1.freebsd.org (Postfix) with ESMTP id CF7D113C489 for ; Mon, 16 Apr 2007 00:40:56 +0000 (UTC) (envelope-from zhangweiwu@realss.com) Received: from localhost (unknown [127.0.0.1]) by bossdog.realss.com (Postfix) with ESMTP id 57DA21C000B for ; Mon, 16 Apr 2007 08:41:06 +0800 (CST) Received: from bossdog.realss.com ([127.0.0.1]) by localhost (bossdog.realss.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 31449-01 for ; Mon, 16 Apr 2007 08:41:05 +0800 (CST) Received: from [192.168.1.200] (58.52.72.124.board.xm.fj.dynamic.163data.com.cn [124.72.52.58]) by bossdog.realss.com (Postfix) with ESMTP id 1EB4A1C000A for ; Mon, 16 Apr 2007 08:41:05 +0800 (CST) Message-ID: <4622C5FC.5070001@realss.com> Date: Mon, 16 Apr 2007 08:40:28 +0800 From: Zhang Weiwu User-Agent: Thunderbird 1.5.0.7 (X11/20060918) MIME-Version: 1.0 To: f-q References: <1176603461.20274.12.camel@joe.realss.com> <20070415054023.GA6596@holestein.holy.cow> <1176625617.22011.16.camel@joe.realss.com> <20070415165309.GA1175@holestein.holy.cow> In-Reply-To: <20070415165309.GA1175@holestein.holy.cow> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: amavisd-new at bossdog.realss.com 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 List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2007 00:40:57 -0000 Parv 写道: > 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). > > Ah, yes, if there are two empty lines this line would create a mistake. The original input file's sections are strictly one-empty-line-divided and one empty line before EOF, thus I was lucky. However I wasn't aware of your point when I wrote this. > >> /^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(?). > > Well, actually order is not important. I forgot to mention this...