Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Efficient way to sum columns in a file

by tlm (Prior)
on Apr 13, 2005 at 11:55 UTC ( #447331=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    # First we make to test files
    % perl -le 'print join(",", map int(rand(1000)), 1..10) for 1..50' > i
    #                                                        V
    perl -lanF, -e '$sum += $F[6]; print "Sum is $sum" if eof()' in1.csv i
    Sum is 48874
  2. or download this
    perl -lanF, -e '$total += $F[6]; $sub += $F[6]; print "Subtotal: $sub"
    + and $sub = 0 if eof; print "Total: $total" if eof()' in1.csv in2.csv
    Subtotal: 23789
    Subtotal: 25085
    Total: 48874
  3. or download this
    perl -lanF, -e '$sum += $F[6]; END{ print "Sum is $sum" }' in1.csv in2

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://447331]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2016-10-27 03:17 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (352 votes). Check out past polls.