From: dblack@... Date: 2007-07-01T22:25:16+09:00 Subject: Re: awk regexp search ---2049402039-172797744-1183296317=:14506 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-172797744-1183296317=:14506" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-172797744-1183296317=:14506 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sun, 1 Jul 2007, baptiste Augui=E9 wrote: > Hi, > > The last bit of a bash program is still resisting me. Here is the code I = used=20 > 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 f= ile,=20 > and get the following value in the same line. I've tried something like, > > output_file=3DIO.readlines('../OUTPUTFILES/Output.dat').to_s > myarray =3D output_file.each_line(/scattering efficiency/){|elt| print=20 > elt.to_s, '\t'} > > but it clearly doesn't work. Here's a little test/demo (using stdin) -- I've added =3D> to the output lines: $ ruby -ne 'puts $1 if /scattering efficiency\s+(\S+)/' scattering efficiency blah =3D> blah nothing this has scattering efficiency just like the other one =3D> just David --=20 * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) ---2049402039-172797744-1183296317=:14506-- ---2049402039-172797744-1183296317=:14506--