From: "baptiste AuguiĆ©" Date: 2007-11-25T22:24:26+09:00 Subject: Re: extract consecutive lines of data Thanks, this didn't work either (the data file contains lines of text before and after the data). I've eventually figured a way playing with different bits of code I found: > # extract space separated numbers from lines 5 to 9 in 'data.txt', > # ignoring header and footer text lines > current = [] > > File.foreach('data.txt') do |line| > if ($. == 5) .. ($. == 9) > current << line.scan(/\S+/).map! {|x| x.to_f} > end > end > p current Best wishes, baptiste On 25 Nov 2007, at 12:15, MonkeeSage wrote: > def input_matrix(file) > File.open(file) { |f| > f.readlines.collect { |line| > line = line.chomp > if line.empty? > then nil > else line.split > end > }.compact.transpose > } > end > > p input_matrix(ARGV[0]) > > ^ Composes matrix from first file given on command line, ignoring > blank lines in file. > > Regards, > Jordan > _____________________________ Baptiste Auguié Physics Department University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag http://projects.ex.ac.uk/atto ______________________________