[olug] One-liner adding machine

Daniel Linder dan at linder.org
Mon Feb 6 20:23:23 UTC 2006



And if you want to see the running total as Jays first example...



awk -F"," '{total += $3; print total, $3}; END{print total}'
test



So, using the same "test" file as Phil used, the output is like
this:

1 1

21 20

24 3

64 40

64



Dan







On Mon, February 6, 2006 13:52, olug at wjjeep.com wrote:

> On Mon, Feb 06, 2006 at 01:28:51PM -0600, Jay Hannah wrote:

>> [SNIP]

>>

>> Let's see your alternate syntaxii, shell gurus :)

> 

> Using awk:

> [olug ~]$ cat test

> a,aa,1

> b,bb,20

> c,cc,3

> d,dd,40

> 

> [olug ~]$ awk -F"," '{total += $3}; END{print total}'
test

> 64

> 

> Phil

> 

> _______________________________________________

> OLUG mailing list

> OLUG at olug.org

> http://lists.olug.org/mailman/listinfo/olug

> 





- - - -

"Wait for that wisest of all counselors, time." -- Pericles

"I do not fear computers, I fear the lack of them." -- Isaac
Asimov

GPG fingerprint:6FFD DB94 7B96 0FD8 EADF  2EE0 B2B0 CC47 4FDE 9B68



More information about the OLUG mailing list