From: "baptiste Auguié" Date: 2007-11-25T23:53:41+09:00 Subject: Re: extract consecutive lines of data Thanks, this is exactly what i was looking for: I just never find my way in these regular expressions, not to mention how to adapt it in Ruby code! On 25 Nov 2007, at 14:22, Robert Dober wrote: > On Nov 25, 2007 2:24 PM, baptiste Auguié wrote: >> Thanks, this didn't work either (the data file contains lines of text >> before and after the data). > > grep is your friend > > 508/8 > cat data.txt && cat detect.rb && ruby detect.rb data.txt > 1 2 3 > Some text > 4 5 6 > more text > 7 8 9 > .42 42 42 > 23 7.3e-8 3.4 > #!/usr/local/bin/ruby > # vim: sw=2 ts=2 ft=ruby expandtab tw=0 nu syn: > > p ARGF.readlines.grep(/^\s*[\.\d]/).map{ |line| > line.chomp.split }.transpose > > [["1", "4", "7", ".42", "23"], ["2", "5", "8", "42", "7.3e-8"], ["3", > "6", "9", "42", "3.4"]] > > BTW don't forget to tell us the mark you got ;) > do you get a mark for a PhD? I can only tell you the imaginary part is gonna be negative, in terms of propagation constant. _____________________________ 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 ______________________________