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 3 of 8 Topic 2180 of 2236
Post > Topic >>

Re: Duplicated output with no condition (easy one)

by ptjm@[EMAIL PROTECTED] (Patrick TJ McPhee) Mar 7, 2008 at 04:32 AM

In article
<78709f89-3881-4ab1-8b45-d0740e89d1cf@[EMAIL PROTECTED]
>,
Atropo  <lxvasquez@[EMAIL PROTECTED]
> wrote:

% I drop a quick one-liner awk to get the avg time (minutes) from a ls
% command. on AIX 5.2
% 
% ls -ltr|awk 'split($8,a,":");t=t+a[2] END {print t,NR ,t/NR }'

This awk program has two actionless patterns and one END action.

 split($0, a, ":")

returns the number of elements in the array a after $8 has been split.
When used as a pattern, it evaluates to "true" whenever $8 is not blank.
similarly, t = t+a[2] will evaluate to "true" whenever t or a[2] is
non-zero.

The effect of a "true" pattern which has no action is to print $0.

What you want is

 ls -ltr|awk '{split($8,a,":");t=t+a[2]} END {print t,NR ,t/NR }'

the braces turn those two patterns into a single action which will
be evaluated for each input record.
-- 

Patrick TJ McPhee
North York  Canada
ptjm@[EMAIL PROTECTED]





 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 Sat May 17 0:14:44 CDT 2008.