On 3/7/2008 6:11 AM, Atropo wrote:
> On 7 mar, 01:53, Lorenz <loren...@[EMAIL PROTECTED]
> wrote:
>
>>>ls -ltr|awk 'split($8,a,":");t=t+a[2] END {print t,NR ,t/NR }'
>>
>>what you have here is three rules whereof two have no explicit action.
>>That is equivalent to:
>>
>> ls -ltr|awk 'split($8,a,":") {print} \
>> t=t+a[2] {print} \
>> END {print t,NR ,t/NR }'
>>--
>>
>>Lorenz
>
>
> Thanks Patrick,Lorenz
>
> Patrick "the braces turn those two patterns into a single action which
> will
> be evaluated for each input record. "
>
> but then the split and the sum will evaluate to true. it will not
> produce output but calculate twice.??
>
> ls -ltr|awk '{split($8,a,":");t=t+a[2]} END {print t,NR ,t/NR }'
> 193 14 13.7857
>
Yes. Isn't that what you want? If you want each record printed as it's
processed, just add a print:
ls -ltr|awk '{split($8,a,":");t+=a[2];print} END{print t,NR,t/NR }'
If you want somethign else, tell us what and provide some expected output.
Ed.


|