On Thu, Feb 2, 2012 at 6:20 PM, Rob Biedenharn
<rob / agileconsultingllc.com> wrote:
>
> On Feb 2, 2012, at 11:51 AM, Cassio Godinho wrote:
>
>> Hello everyone.
>>
>> I'm working on script here and I need do read the 1st and the 10th
>> columns on a file like this
>>
>> R357 0011G1 0 0.0 0 0 0.0 381654.8 7993255.6 827.9 235959
>>
>> As reference I used the code found in this post:
>> http://www.ruby-forum.com/topic/161462#new
>>
>> The difference is on that snippet the user only wanted to read the first
>> column, so I tried something like this
>>
>> file = File.open(" ")
>> columns = []
>> file.each_line do |line|
>> columns << line.split(" ")[0 , 11]

File opening and iteration can be done simpler:

File.foreach do |line|
  a, b = line.split.values_at(0, 10)
end

> R357 0011G1 0 0.0 0 0 0.0 381654.8 7993255.6 827.9 235959".split(" ").values_at(0,10)
> => ["R357", "1235959"]

Minor nitpick: you do not even need the argument to #split because
splitting at whitespace is the default.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/