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

Re: [FWP] Grepping only text files



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.  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

One reason I found this little snippet fun is this very fact: it might 
appear from the docs that -T and -B are opposites [indeed, that perhaps 
you could get away with defining: -T <=> not -B] but that's not the case: 
empty files and nonexitent files break that mold, so they are _not_ 
complements of one another...

 /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
mailto:bernie@fantasyfarm.com     Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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