From: tamouse mailing lists Date: 2012-11-07T13:45:56+09:00 Subject: Re: putting values in one lines Okay: one line: puts IO.readlines("data").grep(/up\s+down\s+aenet/).map{|l| l.split[5]}.join " " On Tue, Nov 6, 2012 at 10:11 PM, tamouse mailing lists wrote: > Ok, more compact: > > output = [] > IO.readlines("data").map{|l| output << l.split[5] if > l.match(/up\s+down\s+aenet/) } > puts output.join " " > > > On Tue, Nov 6, 2012 at 8:15 PM, tamouse mailing lists > wrote: >> Ok, well, pure ruby: >> >> lines = IO.readlines(file) >> lines.each do |l| >> if l.match(/up\s+down\s+aenet/) >> print l.split[5], " " >> end >> end >> print "\n" >> >> >> On Tue, Nov 6, 2012 at 7:37 PM, tamouse mailing lists >> wrote: >>> If you're hoping to do a pure ruby implementation of this, heed the others. >>> >>> If you just need the values, here's the awk: >>> >>> awk 'BEGIN { ORS="" } /up.*down.*aenet/ { print $6 }' file... >>> >>> or, >>> >>> awk -v ORS='' '/up.*down.*aenet/ { print $6 }' file... >>> >>> (you don't need the cat or either grep) >>> >>> >>> On Tue, Nov 6, 2012 at 4:21 PM, Ferdous ara wrote: >>>> Hi, >>>> Dont know how to explain this. >>>> >>>> example , i am doing this >>>> >>>> output=`cat #{file} | grep "up down" | grep "aenet" | awk '{print >>>> $6}'` >>>> puts output >>>> >>>> >>>> So i get this >>>> ae40.0 >>>> ae30.0 >>>> >>>> But i want to output like ae40.0 ae30.0 >>>> >>>> how can i achieve this ?? >>>> >>>> Thanks for your help. >>>> >>>> -- >>>> Posted via http://www.ruby-forum.com/. >>>> >>> >> >