bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep "binary"


From: Bob Proulx
Subject: Re: grep "binary"
Date: Thu, 5 May 2005 22:41:13 -0600
User-agent: Mutt/1.5.9i

Vlad Kudelin wrote:
> the following two commands were issued in a directory containing a
> couple hundreds of subdirectories, each containing a file called
> "txt.txt".
> 
> % grep ^'PATT ' */txt.txt |wc -l
>    9333

In this case 'grep' opens each file itself.  'grep' processes every
file individually.

> % cat */txt.txt | grep ^'PATT '  | wc -l
>   12198

In this case 'cat' opens each file.  'grep' only processes one single
file and that is the standard input to it.  Therefore the first few
bytes of the file are the one single file and the entire input is
either text or binary.

> Would be nice to have the "Binary matching" feature documented in more
> details.
>  * "If the first few bytes of a file indicate that the file contains
> binary data, ...."

You might want to consider using the commands like this.

  find . -name txt.txt -print0 | xargs -r0 grep -aH PATTERN

Then grep would open each file itself but with no danger of
overflowing ARG_MAX.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]