On Aug 7, 7:48 pm, pharrington <xenogene... / gmail.com> wrote:
> On Aug 7, 8:43 pm, Rob Biedenharn <R... / AgileConsultingLLC.com> wrote:
>
> > On Aug 7, 2009, at 8:10 PM, w_a_x_man wrote:
>
> > > On Aug 7, 7:02 pm, w_a_x_man <w_a_x_... / yahoo.com> wrote:
> > >> On Aug 7, 11:44 am, chutsu <chu... / gmail.com> wrote:
>
> > >>> I've got a file that is in two columns, how do I add the second
> > >>> column
> > >>> up as I read through the file?
>
> > >>> Code:
> > >>> #!/usr/bin/ruby
> > >>> file = File.open('some_file.txt')
>
> > >>> # Going through each line
> > >>> file.each do |line|
> > >>>  data = line.split("\t")
> > >>>  total += data[1]        # How do I make this line work?
> > >>> end
>
> > >>> puts total
>
> > >> awk "{t += $2} END {print t}" some_file.txt
>
> > > ruby -ane"BEGIN{$t=0}; $t += $F[1].to_f; END{p $t}" some_file.txt
>
> > Just because you can still write your Perl in Ruby, doesn't mean that
> > you *should*.
>
> > -Rob
>
> > Rob Biedenharn          http://agileconsultingllc.com
> > R... / AgileConsultingLLC.com
>
> just ignore waxman, he's a known troll.

Please ignore this pitiable fellow. He is a well-known
lick-spittle, toad-eater, dimwit, poltroon, catamite, sycophant,
and microcephalic idiot.