How to run linux command in rake file


#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.


#2

On Nov 20, 8:06 am, Vamsi K. removed_email_address@domain.invalid
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: 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. :slight_smile:

purpleworkshops.com


#3

How can I unsubscribe this?

Judy> Date: Fri, 21 Nov 2008 10:45:33 +0100> From:
removed_email_address@domain.invalid> To: removed_email_address@domain.invalid>
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


#4

On Nov 20, 2:55 pm, Jeff removed_email_address@domain.invalid wrote:

p.s. Please don’t say “reply ASAP” when posting. Everyone here is
donating their free time and energy already. :slight_smile:

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"

#5

On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
removed_email_address@domain.invalid 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. removed_email_address@domain.invalid


#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


#7

Gabriel L. wrote:

On Thu, Nov 20, 2008 at 3:06 PM, Vamsi K.
removed_email_address@domain.invalid 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. removed_email_address@domain.invalid

Thanks all of you for the reply.
–vamsi krishna.