Lisp HUG Maillist Archive

Grep and searching subdirectories recursively

(This isn't really an LW question, but it is about how to use LW's
Grep Browser effectively.)

I'm using LWW, just moving to LWW 4.3.6 (from LWW 4.2.7).

Up to now, I've been using the grep program that comes with UnixDos,
which is a set of Unix-like utilities that runs on DOS and Windows
-- see http://www.unixdos.com/ if you're interested.

This version of grep allows me to use something like
    grep -n -d -i "search string" *.lisp

The -d option causes subdirectories to be searched recursively,
and the net effect is to search all .lisp files in the current
directory and in all subdirectories. Perfect!

LWW 4.3 comes with a grep .exe file (the gnu version, I think).
I don't think I can reproduce the above behaviour with this
version of grep.

The following doesn't work:
    grep -n -r -i "search string" *.lisp
(Perhaps it only searches subdirectories whose name ends in
".lisp"?)

This is closer to what I want, but it searches all files including,
for example, .lisp~ files:
    grep -n -r -i "search string" *

I considered:
    grep -n -r -i "search string" *.lisp *\*.lisp *\*\*.lisp
but of course DOS doesn't do wildcard expansion and so this
will not work. (Some DOS *commands* do wildcard expansion, but
the DOS *shell* does not.)

I can continue to use UnixDos's grep, but I can only use that
on one machine (unless I buy another licence), and during my
transition to LW 4.3 I'm running LW 4.2 on my main machine
(which has UnixDos) and LW 4.3 on another machine (which doesn't
have UnixDos).

Is there a way to get standard grep to search all .lisp files
in all subdirectories?


Re: Grep and searching subdirectories recursively

I wrote:

> Is there a way to get standard grep to search all .lisp files
> in all subdirectories?

I guess I can write my own tool that calls grep once for each
directory and which concatenates the output.


Re: Grep and searching subdirectories recursively

>>>>> On Sun, 29 Feb 2004 01:20:51 -0000, "Simon Katz" <sk@nomistech.com> said:

    >> From: "tarvydas" <tarvydas@allstream.net>
    >> 
    >> Use "find" to do the recursion.
    >> 
    >> This almost works (all on one line):
    >> 
    >> \cygwin\bin\find . -name "*.lisp" -exec "C:\Program
    >> Files\Xanalys\Lispworks\lib\4-3-0\etc\grep" -n -i display \{\} ;
    >> 
    >> It searches and finds stuff correctly, but the line number doesn't
    >> appear in the format that Lispworks wants to parse (and I get
    >> "Error" in the Line column, hence, preventing me from double-
    >> clicking and jumping to the spot in the code).
    >> 
    >> So, the trick now is to understand how to get the Lispworks
    >> "grep results parser" to grok the result.  Anybody know how?
    >> 
    >> The cygwin tools (including find) can be found at www.cygwin.com.
    >> 
    >> pt
    >> 

    Simon> Just add -H to the grep args:

    Simon> All on one line:

    Simon> C:\cygwin\bin\find . -name "*.lisp" -exec "C:\Program
    Simon> Files\Xanalys\Lispworks\lib\4-3-0-0\etc\grep" -H -n -i "search-string"
    Simon> \{\} ;

    Simon> Using C:\cygwin\bin\grep instead of the one supplied with LW works
    Simon> fine too.

BTW There is a nice script written in Perl called MG which is like a
combination of "find" and "grep". There are normally two ways of using
"find+grep". You can either launch lots of greps from find (as above)
or you can use find to create a massive command line for grep (using
inline shell evaluation via backquotes). Mg does it all in one process
and doesn't suffer from any command-line size limits. Plus you get
multi-line matching and full Perl regexps.

http://www.srekcah.org/~utashiro/perl/scripts/mg/mg-2.25-man.pdf

__Jason


Updated at: 2020-12-10 08:57 UTC