On Feb 2, 2012, at 11:51 AM, Cassio Godinho wrote:

> Hello everyone.
>=20
> I'm working on script here and I need do read the 1st and the 10th
> columns on a file like this
>=20
> R357    10011G1   0 0.0   0 0 0.0 381654.8 7993255.6 827.9  1235959
>=20
> As reference I used the code found in this post:
> http://www.ruby-forum.com/topic/161462#new
>=20
> The difference is on that snippet the user only wanted to read the =
first
> column, so I tried something like this
>=20
> file =3D File.open(" ")
> columns =3D []
> file.each_line do |line|
> columns << line.split(" ")[0 , 11]

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

(the 11th element is at index 10 when you start from 0)

Array#[] with [0,11] means start from the element at index 0 and take 11 =
elements.

-Rob

> end
>=20
> p columns
>=20
> Aparently It reads every column from 0 to 11
>=20
> --=20
> Posted via http://www.ruby-forum.com/.
>=20