Heh, I actually hadn't realized grep could take a filename argument... I haven't used it much.

It turns out the -l option for grep is what I was looking for. This is the exact output I wanted:
[EMAIL PROTECTED]:~/code/c/kr/1$ grep -lr MAXLINE ~/code/c/kr/1
1-16.c
1-17.c
1-19.c
1-22_bad.c
1-22.c
1-22_old.c
[EMAIL PROTECTED]:~/code/c/kr/1$

I guess I should learn more about grep... it's useful :).

Thanks all and happy New Years Eve,
Martin

Ben Barrett wrote:
Ah, yes, "find" has the "-X" option for xargs compatibility, although that should not be needed if you're using the "-exec" option as Horst suggests.
That was the tip I thought was buried too deeply in my stack :)

Alternately, try "grep -n MAXLINE code/c/kr/1/*" for instance?

    Ben


On 12/31/06, *horst* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Have you considered the use of 'find' , e.g .:
      find . -type f -name 'your*here' -exec grep 'string options
    pattern ...' /dev/null {} \;

      a) /dev/null is there to make grep list the filename (because your
    term is found in {}, not in /dev/null
      b) -type f  excluded directories, symlinks, sockets, ...
         (grep on directories may 'report' binary stuff which can
    confuse your terminal or other 'things' downstream)
      c) if your serach terms are simple text 'fgrep' may be better, not
    just because it's faster -- it saves you a lot of \escaping.
      d) find let's you define you much other handy stuff, ctime, atime,
    inode,...

    I didn't look too closely at your script, but it seemed like you'r not
    testing file type.

    Sorry for the quick&sloppy response.

    Happy New Year to all........................Horst


     > Date: Sun, 31 Dec 2006 13:33:03 -0800
     > From: Martin Kelly <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
     > Reply-To: Eugene Unix and Gnu/Linux User Group <
    [email protected] <mailto:[email protected]>>
     > To: Eugene GNU/Linux Users Group <[email protected]
    <mailto:[email protected]>>
     > Subject: [Eug-lug] Strange shell behavior
     >
     > I have just written a shell script that greps a directory for a
    certain
     > pattern and reports each file that contains the pattern along
    with the
     > filename before it (this is why I wrote it... if I just do a "ls
    | cat | grep
     > pattern" or something like that it will report the text that
    matches but not
     > the filename).
     >
     > I am getting strange behavior in that it works, but sometimes it
    randomly
     > reports the contents of my / directory. This does not always
    happen, only
     > sometimes.
     >
     > Here's an example:
     > [EMAIL PROTECTED]:~$ misc/dirgrep code/c/kr/1/ MAXLINE
     >
     > 1-16.c:
     >
    
--------------------------------------------------------------------------------

     > #define MAXLINE 1000 /backups /bin /boot /dev /etc /home /initrd
    /initrd.img
      ...etc...
     >
    _______________________________________________
    EUGLUG mailing list
    [email protected] <mailto:[email protected]>
    http://www.euglug.org/mailman/listinfo/euglug



------------------------------------------------------------------------

_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug
_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug

Reply via email to