Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Duplicated ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 8 Topic 2180 of 2236
Post > Topic >>

Re: Duplicated output with no condition (easy one)

by Ed Morton <morton@[EMAIL PROTECTED] > Mar 7, 2008 at 07:23 AM

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.




 8 Posts in Topic:
Duplicated output with no condition (easy one)
Atropo <lxvasquez@[EMA  2008-03-06 13:45:07 
Re: Duplicated output with no condition (easy one)
Atropo <lxvasquez@[EMA  2008-03-06 14:00:25 
Re: Duplicated output with no condition (easy one)
ptjm@[EMAIL PROTECTED] (  2008-03-07 04:32:59 
Re: Duplicated output with no condition (easy one)
Lorenz <lorenznl@[EMAI  2008-03-07 06:53:20 
Re: Duplicated output with no condition (easy one)
Atropo <lxvasquez@[EMA  2008-03-07 04:11:46 
Re: Duplicated output with no condition (easy one)
Ed Morton <morton@[EMA  2008-03-07 07:23:12 
Re: Duplicated output with no condition (easy one)
gazelle@[EMAIL PROTECTED]  2008-03-07 13:33:43 
Re: Duplicated output with no condition (easy one)
Lorenz <lorenznl@[EMAI  2008-03-07 14:32:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 23:42:31 CDT 2008.