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

Re: [FWP] Grepping only text files



On Tue, Jun 29, 1999 at 03:00:22PM -0400, Bernie Cosell wrote:
> On 29 Jun 99, at 14:43, Ronald J Kimball wrote:
> 
> > On Tue, Jun 29, 1999 at 11:33:35AM -0700, Bernie Cosell wrote:
> > > I can't exactly figure out why [Unix] grep has never had a command
> > > line switch [if not the default!] only to scan text files.  I use the
> > > following:
> > > 
> > > exec ("grep" , grep  { not -B ; }  @ARGV) ;
> > > 
> > > This is pretty crude with only one redeeming feature [aside from its
> > > utility!]: the test has to be "not -B" -- "-T" won't do...
> 
> > This makes no sense.  There is no reason why you could use "not -B", but
> > could not use "-T".
> 
> Consider the command line:
>     grep -v domain.com sendmail.*
> 
> Since there is no file named '-v' nor a file named 'domain.com', -T will 
> return *FALSE* for those two and breaks the command line.

Oh!  I was missing the syntax of how you were calling this code.  You need
it strip out binary files, but pass through text files and command line
options.  That does make sense now.


> The 'crude' 
> part is that I'm counting on the fact that grep switches and patterns 
> don't look much like file names for the "not-B" to allow them to pass 
> through into the final command line for grep without my having to 
> actually *parse* the command line.  if there's some elegant way to parse 
> the grep command line and *know* which args are supposed to be file names 
> and which aren't, I don't see quite how to do it.  consider:
>      grep -e notafile motd passwd

I see your point.  How about using Tom's tcgrep instead?  It skips binary
files by default, and has a command line switch to include them in the
search.

http://language.perl.com/ppt/src/grep/tcgrep


Ronald

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org