[clue] Piping, xargs, find, grep and such

Sean LeBlanc seanleblanc at comcast.net
Thu Sep 13 15:09:37 MDT 2012


So, I have a question. It seems like this should be easy, but I'm not 
sure how to go about it.

I have a Ruby script that takes as input either:

1. 1-N command line args, assumes those are filenames, and iterates over 
those, translating the files into a readable format - writing on STDOUT.
2. If no args, read STDIN and do the same with that stream of data.


Now, keeping with the Unix philosophy of doing one thing and doing it 
well, I want to string this together with find and such. For example:

find . -name * -print | xargs ./myscript.rb

And that dumps out all the files in a readable format. Great.

Now, I want to combine grep:

find . -name * -print | xargs ./myscript.rb | grep "asearchstring"

And that's all well and good. Now, I want to know what file(s) I get a 
hit in.

Any ideas how to do that?




More information about the clue mailing list