Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Oct 1999 20:39:05 -0700
From:      dannyman <dannyman@dannyland.org>
To:        chat@freebsd.org
Subject:   averaging numbers in a stream
Message-ID:  <19991019203905.B30514@stumpy.dannyland.org>

next in thread | raw e-mail | index | archive | help
ocassionally i wanna get stupid with pipes.

grep 'current members' mail/cron | awk '{print $1}' | sort | uniq -c | ( echo '(' && awk '{print $1"*"$2"+"}' && echo '0)/' && grep 'current members' mail/cron | wc -l ) | xargs echo > /tmp/tmp && echo `cat /tmp/tmp|bc`

Those first two commands create a stream of numbers, one per line, that I wish
to average.  Is there a cleaner way to do this, all on one line, with a fairly
standard Unix shell?  In my case, tcsh.

Not that this is actually IMPORTANT to me, I'm just having fun.

Personally, I think I'm cheating ... it's one thing to ... | ... ( ... && ...
&& ... && ... ) ... | but the last && echo bit is really just there because
butting the rest of the expression in backticks is just way nasty.

Anyways, back to your dreary little lives ...

-dman

-- 
dannyman - http://www.dannyland.org/~dannyman/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




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