The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: grep and xargs
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 11-23-2007
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Quote:
Originally Posted by freakygs View Post
it worked but the grep command ran for multiple times, ...
xargs can/will do that. Think of running something like 'find . -type f -exec grep foo {}\;' - that will exec 'grep' once for each file found. Now, running 'find . -type f | xargs grep foo' will minimize the number of time grep is called. It still may need to be called more than once, since there is a limit to the length of a command line, depending on your shell and architecture - for example, mine is roughly 32k. If I ran a huge search on a large source branch, I'd expect to search well over 32k files, so even in the best case scenario, xargs could not possibly build the "ideal" command line for me.