Look! An xargs!! (Re: recursive grep)

Conor P. Cahill cpcahil at virtech.UUCP
Mon Sep 4 01:23:30 AEST 1989


In article <4026 at buengc.BU.EDU>, bph at buengc.BU.EDU (Blair P. Houghton) writes:
> Okay, kids.  Shell script 101 is now in session.
> 
> Try this, after putting  it in a file and turning on the execute flag.
> 
>     while read arrrrg
>     do
> 	    $* $arrrrg
>     done
> 

The reason why xargs was suggested was so the following type of operation
could be executed without fork/execing a grep for every file.

	find . [args] -print -exec grep [RE] {} ";"

Xargs will use the following structure AND process as many files
as it can in a single iteration:

	find . [args] -print | xargs grep [RE]

So your solution would be somewhat less effecient than using the 
find to exec the grep itself, since you would require a pipe,
a shell, and then the fork/exec FOR every file.



-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list