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

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

Re: grep


From: Bob Proulx
Subject: Re: grep
Date: Mon, 6 Oct 2008 15:24:14 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

Jérôme Arfouche wrote:
> my grep version is "grep (GNU grep) 2.5.1"

That should be okay.  I tested using 2.5.1 and I could not recreate
your failure.  I used Debian Stable for my test and it was okay for me.

> and i have this problem when i try to do this:
> [...fixed...] grep -c -d skip "\#\!" * | grep :0 | wc -l
> basically it's supposed to look for FILES (skip dir) that don't have the
> shebang line and count them, that's it
> for some reason it keeps counting my directories with it

I do not see that myself.  See the example that I posted:

> >  mkdir t && cd t
> >  mkdir a b c
> >  echo foo1 > a/one
> >  echo foo2 > b/two
> >  echo foo3 > c/three
> >  echo foo4 > four
> >
> >  grep -d skip -c foo ./*
> >  ./four:1
> >
> >  grep -c -d skip foo ./*
> >  ./four:1

The skip seems to be working okay to me.  By contrast if I change this
to be 'read' then I see what you are describing.  I am using grep
version 2.5.1 for this testing.

  grep -d read -c foo ./*
  ./a:0
  ./b:0
  ./c:0
  ./four:1

Unfortunately since it seems to be behaving here unless someone else
can replicate the problem it means that you are the only one able to
debug your problem further.

Alternatively I believe that 'find' is the better tool for the job.
Try this instead:

  find . -maxdepth 1 -type f -exec grep -c "#\!" {} + | grep -c :0

The '!' only needs to be escaped for csh and bash history expansion.
The grep argument will be seen as "#!" after shell processing.  Other
shells might need or not need this escaping or using '#!' is common on
unix shells.  The '#' is okay without escaping.  Sometimes unused
escapes are then used later so it is better to avoid them.

Bob




reply via email to

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