From: "baptiste Auguié" Date: 2007-07-02T00:27:28+09:00 Subject: Re: awk regexp search Thanks everybody, this piece of code works fine for me, output_file.each { |line| case line when /scattering efficiency/ qsca << line.split(/\s+/)[4] end } although I realize now that "output_file" may contain a duplicate of the line I want to extract. How can I specify to take only the last occurrence? The file to parse looks something like that, > a few lines ... > > > scattering efficiency = 2.8009E-08 > extinction efficiency = 4.9374E-06 > > some lines in between ... > > > scattering efficiency = 2.7957E-08 > extinction efficiency = 4.9374E-06 > ... On 1 Jul 2007, at 15:51, Robert Dober wrote: > On 7/1/07, dblack@wobblini.net wrote: >> Hi -- >> >> On Sun, 1 Jul 2007, baptiste Augui� wrote: >> >> > Hi, >> > >> > The last bit of a bash program is still resisting me. Here is >> the code I used >> > before: >> > >> > awk '/scattering efficiency/{print $4}' ../OUTPUTFILES/Output.dat >> > >> > >> > How would you do that in Ruby? I just need to locate this regexp >> in the file, >> > and get the following value in the same line. I've tried >> something like, >> > > >> $ ruby -ne 'puts $1 if /scattering efficiency\s+(\S+)/' >> scattering efficiency blah >> => blah >> nothing >> this has scattering efficiency just like the other one >> => just >> > The problem is that we have no idea where "scattering efficency" is > relatively to $4 :( > However > > ruby -ane 'puts $F[3] if /scattering efficency/' ../ton/beau/fichier > > does the same as the awk script above > this piece of code needs to be part of a script, not a one line call - > how would that work in a Ruby script? > Side Remark: > domage que l'on ne puisse utiliser mes options pr�f�r�es: -anpe ;) ; ) > > > Robert Thanks, baptiste