hi everyone,
I’m very, very fresh in ruby so
I’m looking for help with a small problem. I’ve got a log file from wget
and I have to evaluate average download speed when downloading is still
going, so I’m trying to do this
File.open(name) do |file|
while line=file.gets
tab=%w(line.split)
end
end
but how can I evaluate this 8th column from wget-log each line, I’m not
even sure about this few lines above
this line is almost certainly wrong, what you wanted was probably
tab = line.split
to get the value of the 8th column you’d do
eighth_column = tab[7]
thx for quick answer
hehe you’re right I was trying this but eclipse with DLTK is not to good
for ruby, it’s showing wrong results I think I will use vim like for
bash scripting
but I still don’t know how to put together all this numbers
hi everyone,
I’m very, very fresh in ruby so
I’m looking for help with a small problem. I’ve got a log file from wget
and I have to evaluate average download speed when downloading is still
going, so I’m trying to do this
File.open(name) do |file|
while line=file.gets
tab=%w(line.split)
this line is almost certainly wrong, what you wanted was probably
tab = line.split
to get the value of the 8th column you’d do
eighth_column = tab[7]
for ruby, it’s showing wrong results I think I will use vim like for
bash scripting
but I still don’t know how to put together all this numbers
I’ m not sure what you mean by “put together all this numbers.” A good
thing to do when you are trying to write a program is to play with it
irb.
You get immediate feedback.
but I still don’t know how to put together all this numbers
I’ m not sure what you mean by “put together all this numbers.” A good
thing to do when you are trying to write a program is to play with it
irb.
You get immediate feedback.
I’ve got this few lines
while line=file.gets
tab=line.split
c8=tab[7].to_f
end
and it works. Results of is it’s like that
22121.12
4232.1
42353.90
322.0
when I’ll add line like this “puts sum=+c8” just before end nothing
happens, all I want is to add one number to another (evaluate it)
ok, guys I solved this very tough problem
and this is a solution for someone who will need it for any reason, but
I have another question how can I do this code more Ruby (I mean more
solid and nice in ruby style) because it seems for me very vulgar
sum=0.0
count=0
impr_count=0
if ARGV[0]!=nil then
File.open(ARGV[0]) do |file|
while line=file.gets
if line=~(/^([0-9]+)K/&&/%/)
count+=1
end
impr_count+=1
tab=line.split
c8=tab[7].to_f
sum+=c8
end
eval=impr_count-count
puts
puts “Av. download speed: #{sum/count} KB/s”
print "I’ve read #{count} proper & "
eval>1 ? (puts “#{eval} improper lines”) : (puts “#{eval} improper
line”)
puts
end
else
puts
print “Corupted or missing file or file path!!!\n\tPlease repeat
command with correct data\n”
puts
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.