From: Robert Klemme Date: 2004-03-11T21:24:42+09:00 Subject: Re: Novice question, tranlate awk code to ruby code "Chad Fowler" schrieb im Newsbeitrag news:66E60584-72F3-11D8-B5D4-000A95BDA42A@chadfowler.com... > > On Mar 10, 2004, at 4:19 PM, Horacio Castellini wrote: > > > Hi everyone: > > I'm a novice ruby user, but ancient user in Linux world. We assume > > have a data file with two data field in two columns. In awk program > > when I > > like time them a script code may be: > > > > { > > print $1*$2 > > } > > > > for example I can use "% cat foo.dat|awk -f times.awk" d'accorde. Well, > > how can I do this in ruby code? > > > > Hi. Here's a very awk-like way to do it: > > cat foo.dat |ruby -ane 'puts $F[0].to_i * $F[1].to_i' This entitles you to a useless cat award. Just do ruby -ane 'puts $F[0].to_i * $F[1].to_i' foo.dat Or ruby -ane 'puts Integer($F[0]) * Integer($F[1])' foo.dat robert