X
x1
--Cool to use throw ruby into the -exec but I would just use grep in
that scenerio.
that scenerio.
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'`
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.
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 d= o
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 =3D~ /a.rb/} '
-a
--
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
| 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
I apologize for using a brain dead example. I was more excited about t= he
prospect of hitting all files under the current directory recursively, = =20
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 a= t
it's man page.
Pat said: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.
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/} '
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/} '
Hi --
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
Pat Maddox said:Or you can use the tools designed for finding stuff
find . -name "*.txt" | xargs grep Hello
That version will work for all files.
Pat said: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.
Pat
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.
Know an OS where that is allowed?
ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
That doesn't seem to do anything . .
ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
That doesn't seem to do anything . .
then you probably don't have any files named 'a.rb' under the current
directory - i seem to have several hundred ;-)
Hi --
ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
That doesn't seem to do anything . .
then you probably don't have any files named 'a.rb' under the current
directory - i seem to have several hundred ;-)
Or abrb, or acrb, or airbag, or....
Hi --
On Tue, 27 Dec 2005, Philip Rhoades wrote:
ruby -e' puts Dir["**/**"].select{|e| e =~ /a.rb/} '
That doesn't seem to do anything . .
then you probably don't have any files named 'a.rb' under the current
directory - i seem to have several hundred ;-)
Or abrb, or acrb, or airbag, or....
indeed. or diectories. that's the nice thing about using select:
ruby -e' puts Dir["**/**"].select{|e| test ?f, e and e =~ /^a\.rb$/} '
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.