From: Robert Dober Date: 2007-07-02T03:09:29+09:00 Subject: Re: awk regexp search On 7/1/07, baptiste Augui� wrote: > > 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? I am not sure I understand, this command can be put into a bash script as the awk example above, if however you want to replace the bash script by a Ruby script it will be necessary to read the File explicitly puts File.readlines("/le/beau/fichier"/).grep(/scattering efficency/). map{|line| line.split[3]} or only the first puts File.readlines("/le/beau/fichier"/).grep(....).first.split[3] or if performance is an issue and you do not want to read further lines File.each("/le/grand/fichier") do |line| next unless /.../ === line puts line.split[3] break end Cheers Robert > > > Side Remark: > > domage que l'on ne puisse utiliser mes options pr�f�r�es: -anpe ;) > > ; ) > > > > > > > > Robert > > Thanks, > > baptiste > > > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck