Hi --

On Wed, 31 Jul 2002, Maur?cio wrote:

>     Guys,
>
>     I have a file like this:
>
>    1182001       G     -5.862926E-06     -4.551246E-04     -8.286275E-07
> 876
> -CONT-                 -8.112655E-06     -3.389444E-08      5.149248E-06
> 877
>    1182002       G     -8.318727E-06     -6.311623E-04     -1.682066E-06
> 878
> -CONT-                 -1.082094E-05     -3.322333E-08      5.278418E-06
> 879
>    1182003       G     -1.142483E-05     -8.031433E-04     -4.946876E-06
> 880
> -CONT-                 -1.385842E-05     -8.260204E-08      5.663920E-06
> 881
>
>
>     How do I say: in a set of (number G number number1 number number
> end-of-line --CONT- number number2 number number end-of-line), I want to
> know number1 and number2?

(Performing some joins on the above, as per your verbal description of
where the newlines are....)

This little demo doesn't do much with the numbers, other than put them
all into an array, and you might want to do more checks... but the
principle (determining an index and then splitting the line and
grabbing the element at the index) might be useful:

res = DATA.readlines.map do |line|
  index = case line
          when /G/      then 3
          when /CONT/   then 2
          else          raise "Bad line: #{line}"
          end
  line.split[index]
end

p res

__END__
   1182001       G     -5.862926E-06     -4.551246E-04     -8.286275E-07 876
-CONT-                 -8.112655E-06     -3.389444E-08      5.149248E-06 877
   1182002       G     -8.318727E-06     -6.311623E-04     -1.682066E-06 878
-CONT-                 -1.082094E-05     -3.322333E-08      5.278418E-06 879
   1182003       G     -1.142483E-05     -8.031433E-04     -4.946876E-06 880
-CONT-                 -1.385842E-05     -8.260204E-08      5.663920E-06 881


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav