This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: grep - limited number of arguments?


"Thomas Baker" <thomas.baker@bi.fhg.de> wrote:
> One difficulty I have found, however, is limitations (or so
> it would seem) on the number of arguments that the command
> "grep" can take.

You can't (portably) rely on anything much more than a few thousand
characters in a single command line. The minimum requirement for a
Posix system is 4096 (see <limits.h>). The usual technique is to use
`xargs', as:

    ls | xargs grep pattern

(or even `ls | xargs grep pattern /dev/null' to catch the case with
only one argument being given to grep and it changing behaviour).

This splits up the incoming arguments and invokes grep repeatedly, a
batch of the arguments at a time. It's particularly useful with `find'
and it's got lots of lovely options to play with too :-)

It would be nice to allow arbitrary command lines, but I've never
(knowingly) used a system that did so.

// Conrad




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]