Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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
    +n1.csv
    ...
    #                                                        V
    perl -lanF, -e '$sum += $F[6]; print "Sum is $sum" if eof()' in1.csv i
    +n2.csv
    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
    +.csv
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-12-22 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (126 votes), past polls