From: Janis Papanagnou on
On 14/07/10 20:38, thdyoung(a)googlemail.com wrote:
> Thank you Janis for a clear explanation. I get your first line.
>
> Second line: how is 'f' set ? Does it have a default when called ?
>
> Is ' f ' some kind of standard usage in awk ?

It's a variable, per default initialized with 0 (simply put).

The variable f is, in the awk program, only set/unset while
performing the first line. That implies; whenever awk reads
a line which doesn't start with a blank - which is actually
a line with a date, then - the flag is set to 1, if the date
in field 1 matches, or unset to 0, if the date doesn't match.
On the next date line that flag f will be reconsidered for
setting/unsetting, depending on the '~' match operation that
compares the requested date.

The (global) variables in awk keep their value until changed.

The second line will always be exectuted (for every line) if
the flag is set (and if it's a line starting with a blank as
well) and the corresponding action executed, depending on the
flag status; the flag is never changed in the second line.

Janis

>
> Tom
>
>> Reformatted, slightly rearranged, and default action added gives
>>
>> !/^ / && f=($1~d) { print $0 }
>> /^ / && f { print $0 }
>>
>> First line:
>> whenever a line starts not with white space,
>> and the flag is set, which depends on
>> the first field matches the date,
>> print the line
>> Second line:
>> whenever a line starts with white space,
>> and the flag is set,
>> print the line
>>
>> Janis
>
>
>

From: thdyoung on
thanks once again, Janis.

the second line is grabbing the lines which begin w a space

why is the unset f of any use in the second line ?

surely testing for whitespace at the beginning of the line is enough.

i too have run the code and it grabs three lines: one starting w the
reqd date, the other two ('S/N', 'etc...') starting w space.

leaving out the 'f &&' part of the second has no impact so far as I
can see on the code output: it delivers the same 3 lines.

what am I not getting ?

Tom

From: Janis Papanagnou on
On 15/07/10 11:38, thdyoung(a)googlemail.com wrote:
> thanks once again, Janis.
>
> the second line is grabbing the lines which begin w a space
>
> why is the unset f of any use in the second line ?

Its value is controlling whether the line is printed or not.
Since f is only set to 1 on a date line with matching date,
the subsequent corresponding lines of the block are printed.
Since f is only set to 0 on a date line with non-matching date,
the subsequent corresponding lines of the block are not printed.

>
> surely testing for whitespace at the beginning of the line is enough.
>
> i too have run the code and it grabs three lines: one starting w the
> reqd date, the other two ('S/N', 'etc...') starting w space.
>
> leaving out the 'f &&' part of the second has no impact so far as I
> can see on the code output: it delivers the same 3 lines.
>
> what am I not getting ?

Try it on a block with matching date and then on a block with
non-matching date.

Janis

>
> Tom
>

From: thdyoung on
So is this it ....

On lines that start w a space, that are immediately after the ones
beginning w the required date, ' f ' remains set to 1

This is picked up by:

/^ / && f { print $0 }

If this is right, it also seems to me that an important attribute of f
is that it remains set until it is unset. It is not auto-reset to 0
for each new line of input.

I think Janis was trying to say this when she wrote previously: <<
Since f is only set to 1 on a date line with matching date,
the subsequent corresponding lines of the block are printed. >>

Tom


From: Janis Papanagnou on
On 15/07/10 16:16, thdyoung(a)googlemail.com wrote:
> So is this it ....
>
> On lines that start w a space, that are immediately after the ones
> beginning w the required date, ' f ' remains set to 1
>
> This is picked up by:
>
> /^ / && f { print $0 }
>
> If this is right, it also seems to me that an important attribute of f
> is that it remains set until it is unset. It is not auto-reset to 0
> for each new line of input.

Right. This is what I wrote upthread:

"The (global) variables in awk keep their value until changed."


>
> I think Janis was trying to say this when she wrote previously: <<
> Since f is only set to 1 on a date line with matching date,
> the subsequent corresponding lines of the block are printed. >>
>
> Tom
>
>