hi all, i need to grep a word count from a text file and i want to display the count. i need all the above in a rake file , i tried it by using today_count= system("grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc -l") puts "today count is :#{today_count}" but today_count returns ''true'' instead of count. plz reply ASAP. Thanks.. --vamsi. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 20, 8:06 am, Vamsi Krishna <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi all, > > i need to grep a word count from a text file and i want to display the > count. > i need all the above in a rake file , i tried it by using > > today_count= system("grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc > -l") > puts "today count is :#{today_count}" > > but today_count returns ''true'' instead of count. > > plz reply ASAP. > > Thanks.. > --vamsi. > -- > Posted viahttp://www.ruby-forum.com/.Try backticks instead: output = `grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc` backticks will return whatever went to stdout. For system(), rtfm: http://ruby-doc.org/core/ Jeff p.s. Please don''t say "reply ASAP" when posting. Everyone here is donating their free time and energy already. :-) purpleworkshops.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Vamsi Krishna wrote:> hi all, > > i need to grep a word count from a text file and i want to display the > count. > i need all the above in a rake file , i tried it by using > > today_count= system("grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc > -l") > puts "today count is :#{today_count}" > > but today_count returns ''true'' instead of count. > > > plz reply ASAP. > > > Thanks.. > --vamsi.Vamsi, I think here you using ''time'' is a variable, instead of using that variable try to append that var by using ''<<'' --nan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
How can I unsubscribe this? Judy> Date: Fri, 21 Nov 2008 10:45:33 +0100> From: rails-mailing-list@andreas-s.net> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Subject: [Rails] Re: how to run linux command in rake file> > > Vamsi Krishna wrote:> > hi all,> > > > i need to grep a word count from a text file and i want to display the> > count.> > i need all the above in a rake file , i tried it by using> > > > today_count= system("grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc> > -l")> > puts "today count is :#{today_count}"> > > > but today_count returns ''true'' instead of count.> > > > > > plz reply ASAP.> > > > > > Thanks..> > --vamsi.> > > Vamsi,> I think here you using ''time'' is a variable, instead of using that > variable try to append that var by using ''<<''> > --nan> > > -- > Posted via http://www.ruby-forum.com/.> > _________________________________________________________________ AirNZ vs Pacific Blue & heaps more! Book now. http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fadsfac%2Enet%2Flink%2Easp%3Fcc%3DHOT056%2E76008%2E0%26clk%3D1%26creativeID%3D108913&_t=773821977&_r=HoT_tagline&_m=EXT --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 20, 2:55 pm, Jeff <cohen.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> p.s. Please don''t say "reply ASAP" when posting. Everyone here is > donating their free time and energy already. :-)Fred Cheung wrote a little article on his blog about that; http://spacevatican.org/2008/11/20/asap "Things most likely to make me not reply to a message on a mailing list: This is urgent Plz reply ASAP" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Nov 20, 2008 at 3:06 PM, Vamsi Krishna <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hi all, > > i need to grep a word count from a text file and i want to display the > count. > i need all the above in a rake file , i tried it by using > > today_count= system("grep -R ''time'' oct_10.txt | grep -R ''hi'' | wc > -l") > puts "today count is :#{today_count}" > > but today_count returns ''true'' instead of count.normal, system() return true or false only, not stdout... you can use ``, popen, or code that in ruby. today_count = File.open(''oct_10.txt'').grep(''time'').grep(''hi'').size (not tested) -- Gabriel Laskar <bibi.skuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gabriel Laskar wrote:> On Thu, Nov 20, 2008 at 3:06 PM, Vamsi Krishna > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> but today_count returns ''true'' instead of count. > normal, system() return true or false only, not stdout... > > you can use ``, popen, or code that in ruby. > > today_count = File.open(''oct_10.txt'').grep(''time'').grep(''hi'').size > > (not tested) > -- > Gabriel Laskar <bibi.skuk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>Thanks all of you for the reply. --vamsi krishna. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---