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

Lorin Ricker Lorin at RickerNet.us
Sun Sep 16 17:16:34 MDT 2012


I'm not quite sure that just outputting the filename from your script to 
grep would do it, as grep's just looking for your pattern 
"asearchstring" to report, and putting "filea", "fileb" (etc) into the 
std-output stream isn't going to trigger a match that grep would report.

When grep opens the files by itself, it "knows" the filename, and 
reports it as part of its output as it finds each search-string 
instance...  That's a special case, different from seeing filenames 
embedded in the std-output that it's searching through in the pipe.

A pipeline like this puts grep into a different mode: Just report 
text-lines where it finds the search-string.

BTW, this isn't a "Ruby problem"... if your "myscript" was written in 
Python, Perl or bash, it'd be the same problem.

I gotta think about this some more... ;-)

-- Lorin

On 09/13/2012 03:12 PM, Raymond DeRoo wrote:
> Sean:
>
>> find . -name * -print | xargs ./myscript.rb | grep "asearchstring"
>
> Your script would need to provide the name of the file as part its output.
>
> Best Regards,
> Rayond
>
>


More information about the clue mailing list