[olug] One-liner adding machine
George Neill
georgen at neillnet.com
Mon Feb 6 19:39:06 UTC 2006
Somewhat off "topic", awk and all, but none-the-less just as useful ...
awk -F',' 'BEGIN{sum=0;}{ sum+=$3 }END{print sum}' t.out
Later,
George
Quoting Jay Hannah <jay at jays.net>:
>
> Given a comma delimited file w/ numbers in the 3rd location, add up all
> those numbers.
>
> $ perl -anF',' -e '$total += $F[2]; print "$F[2] $total\n";' myfile.txt
> | head
> 25000 25000
> 20946 45946
> 11592 57538
> 500 58038
> 500 58538
> 500 59038
> 500 59538
> 500 60038
> 500 60538
> 500 61038
>
> Neat! Saved myself from having to write a 4 line program! -grin-
>
> This is my first time using -a and -F. "perldoc perlrun" for more info.
>
> Let's see your alternate syntaxii, shell gurus :)
>
> j
> Omaha Perl Mongers: http://omaha.pm.org
>
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>
> !DSPAM:43e7a387120321728452263!
>
>
More information about the OLUG
mailing list