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'`
unfortunately that version would fail if there were any spaces in the
filenames.
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'`
unfortunately that version would fail if there were any spaces in the
filenames.
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'`
unfortunately that version would fail if there were any spaces in the
filenames.
At Tue, 27 Dec 2005 12:57:53 +0900,
Gary Watson wrote in [ruby-talk:172611]:
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'`
unfortunately that version would fail if there were any spaces in the
filenames.
ruby -ne 'BEGIN{ARGV.replace(Dir[ARGV.join("\0")])}; print if /Hello/' '**/*.txt'
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'`
--
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
I apologize for using a brain dead example. I was more excited about the
prospect of hitting all files under the current directory recursively, not
the actual processing I used in my examples. Thanks for the pointer to
xargs. I didn't know about that one, I'll have to take a closer look at
it's man page.
···
On Tue, 27 Dec 2005 13:05:32 +0900, Pat Maddox wrote:
Or you can use the tools designed for finding stuff
find . -name "*.txt" | xargs grep Hello
That version will work for all files. You can play with find to match
any file you want.
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
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
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
···
On Tue, 27 Dec 2005, ara.t.howard@noaa.gov wrote:
On Tue, 27 Dec 2005, Gary Watson wrote:
--
David A. Black
dblack@wobblini.net
"Ruby for Rails", from Manning Publications, coming April 2006!
In article
<810a540e0512262005s3e4c971bl2f2915954c34965f@mail.gmail.com>,
Or you can use the tools designed for finding stuff
find . -name "*.txt" | xargs grep Hello
That version will work for all files.
<educational type="but not ruby related">
Not quite. For better (maximum?) robustness, pass '-print0' to find and
'-0' to xargs. That will handle filenames with spaces and/or quotes
correctly. (If your filenames have bytes with binary value zero in them,
you still will be out of luck)
</educational>
I know Im a n00b, but I think more than anything, its good to see you so excited about Ruby. Learning new things really is fun in Ruby.
···
On Mon, 26 Dec 2005 20:22:52 -0800, Gary Watson <pfharlock@yahoo.com> wrote:
I apologize for using a brain dead example. I was more excited about the
prospect of hitting all files under the current directory recursively, not
the actual processing I used in my examples. Thanks for the pointer to
xargs. I didn't know about that one, I'll have to take a closer look at
it's man page.
On Tue, 27 Dec 2005 13:05:32 +0900, Pat Maddox wrote:
Or you can use the tools designed for finding stuff
find . -name "*.txt" | xargs grep Hello
That version will work for all files. You can play with find to match
any file you want.
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:
<educational type="but not ruby related">
Not quite. For better (maximum?) robustness, pass '-print0' to find and
'-0' to xargs. That will handle filenames with spaces and/or quotes
correctly. (If your filenames have bytes with binary value zero in them,
you still will be out of luck)
</educational>
then you probably don't have any files named 'a.rb' under the current
directory - i seem to have several hundred
cheers.
-a
···
On Tue, 27 Dec 2005, Philip Rhoades wrote:
ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
That doesn't seem to do anything . .
--
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
Would any mad enough rubyists start the equivalent of http://ppt.perl.org/? For the impatient, "perl power tools: unix
reconstruction project" is an on-going attempt at writing (most of) the
BSD command set in Perl.
Not quite as mad as BASIC in TeX, but potentially useful indeed.
<educational type="but not ruby related">
Not quite. For better (maximum?) robustness, pass '-print0' to find and
'-0' to xargs. That will handle filenames with spaces and/or quotes
correctly. (If your filenames have bytes with binary value zero in them,
you still will be out of luck)
</educational>