Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Apr 2007 08:40:28 +0800
From:      Zhang Weiwu <zhangweiwu@realss.com>
To:        f-q <freebsd-questions@freebsd.org>
Subject:   Re: [OT] can sed handle this situation? (might require variable)
Message-ID:  <4622C5FC.5070001@realss.com>
In-Reply-To: <20070415165309.GA1175@holestein.holy.cow>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4622C5FC.5070001>