[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Found a neat trick for doing recursive one-liners

Ara.T.Howard

12/27/2005 4:14:00 AM

8 Answers

x1

12/27/2005 4:51:00 AM

0

Ara, I always love your examples! :-) Please keep contributing to the
community!!

BTW, I have the process management class working like a champ.. I'll
share the code with you later!



On 12/26/05, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Tue, 27 Dec 2005, Gary Watson wrote:
>
> > This is probably something everyone in here already knows about, but I
> > thought it was cool enough that I wanted to post about it.
> >
> > If you want to create a one liner to say search all the *.txt files
> > in and under the current directory for text matching "Hello", you can do
> > this
> >
> > find -name '*.txt' -exec ruby -ne 'print if /Hello/' '{}' ';'
> >
> > I know you can do this in pure ruby in like 3 lines if you use the Find
> > module, but I really wanted to do it with a one liner. Earlier I tried
> > something like this
> >
> > ruby -ne 'print if /Hello/' `find -name '*.txt'`
>
> ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
>
> -a
> --
> ===============================================================================
> | ara [dot] t [dot] howard [at] noaa [dot] gov
> | all happiness comes from the desire for others to be happy. all misery
> | comes from the desire for oneself to be happy.
> | -- bodhicaryavatara
> ===============================================================================
>
>
>


Phil Rhoades

12/27/2005 5:20:00 AM

0

Ara,


On Tue, 2005-12-27 at 13:22 +0900, ara.t.howard@noaa.gov wrote:
> On Tue, 27 Dec 2005, Gary Watson wrote:
>
> > This is probably something everyone in here already knows about, but I
> > thought it was cool enough that I wanted to post about it.
> >
> > If you want to create a one liner to say search all the *.txt files
> > in and under the current directory for text matching "Hello", you can do
> > this
> >
> > find -name '*.txt' -exec ruby -ne 'print if /Hello/' '{}' ';'
> >
> > I know you can do this in pure ruby in like 3 lines if you use the Find
> > module, but I really wanted to do it with a one liner. Earlier I tried
> > something like this
> >
> > ruby -ne 'print if /Hello/' `find -name '*.txt'`
>
> ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '


That doesn't seem to do anything . .

Phil.
--
Philip Rhoades

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney NSW 2001
Australia
Mobile: +61:(0)411-185-652
Fax: +61:(0)2-8221-9599
E-mail: phil@pricom.com.au




dblack

12/27/2005 10:37:00 AM

0

Michael Fellinger

12/27/2005 10:46:00 AM

0

I really prefer the simple variant...
ruby -e 'puts Dir["**/a*.{rb}"]'

finds all .rb that start with 'a', recursive of course :)

Am Dienstag, 27. Dezember 2005 11:36 schrieb dblack@wobblini.net:
> Hi --
>
> On Tue, 27 Dec 2005, ara.t.howard@noaa.gov wrote:
> > On Tue, 27 Dec 2005, Gary Watson wrote:
> >> This is probably something everyone in here already knows about, but I
> >> thought it was cool enough that I wanted to post about it.
> >>
> >> If you want to create a one liner to say search all the *.txt files
> >> in and under the current directory for text matching "Hello", you can do
> >> this
> >>
> >> find -name '*.txt' -exec ruby -ne 'print if /Hello/' '{}' ';'
> >>
> >> I know you can do this in pure ruby in like 3 lines if you use the Find
> >> module, but I really wanted to do it with a one liner. Earlier I tried
> >> something like this
> >>
> >> ruby -ne 'print if /Hello/' `find -name '*.txt'`
> >
> > ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
>
> We've strayed a little from the original thing, but along those lines
> you could also do:
>
> ruby -e 'puts Dir["**/**"].grep(/a\.rb/)'
>
> (just guessing about the \. part :-)
>
> or maybe even:
>
> ruby -e 'puts Dir["**/*a.rb*/"]
>
>
> David

Ara.T.Howard

12/27/2005 4:49:00 PM

0

dblack

12/27/2005 5:36:00 PM

0

Ara.T.Howard

12/27/2005 5:39:00 PM

0

dblack

12/27/2005 5:49:00 PM

0