vamsi
November 20, 2008, 3:06pm
1
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
November 20, 2008, 3:55pm
2
On Nov 20, 8:06 am, Vamsi K. [email protected]
wrote:
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: RDoc Documentation
Jeff
p.s. Please don’t say “reply ASAP” when posting. Everyone here is
donating their free time and energy already.
purpleworkshops.com
vamsi
November 21, 2008, 11:51am
3
How can I unsubscribe this?
Judy> Date: Fri, 21 Nov 2008 10:45:33 +0100> From:
[email protected] > To: [email protected] >
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.net%2Flink.asp%3Fcc%3DHOT056.76008.0%26clk%3D1%26creativeID%3D108913&_t=773821977&_r=HoT_tagline&_m=EXT
vamsi
November 21, 2008, 3:27pm
4
On Nov 20, 2:55 pm, Jeff [email protected] 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;
"Things most likely to make me not reply to a message on a mailing
list:
This is urgent
Plz reply ASAP"
vamsi
November 22, 2008, 12:41am
5
On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
[email protected] 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 L. [email protected]
vamsi
November 21, 2008, 10:45am
6
Vamsi K. 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
vamsi
November 22, 2008, 7:38am
7
Gabriel L. wrote:
On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
[email protected] 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 L. [email protected]
Thanks all of you for the reply.
–vamsi krishna.