[off-topic] Re: [GiNaC-list] well, here's the latest story on recursive grep

John Pye john.pye at student.unsw.edu.au
Wed Jul 19 01:48:14 CEST 2006


Hi Richard,

The grep behaviour for "grep -r PATTERN *.cc" is not unexpected. Grep
will only recurse into directories matching *.cc in this case. A
solution that I tend to use is to bring 'xargs' and 'find' into the
picture as follows:

find . -name "*.cc" | xargs grep "Illegal number syntax"

Under Linux there are also tools like 'regexxer' and 'cscope' that are
very useful with this sort of stuff. OpenGrok is new and should run on
Windows as well (it's Java). For Windows, I also like the 'find in
files' feature in TextPad (not free).

Cheers
JP

Richard Haney wrote:

>Effective recursive search with grep seems to be an important skill
>when trying to debug CLN and GiNaC.
>
>I tried a bit more searching on the Internet and tried a few more
>combinations with my existing versions of grep.  Many of the
>alternative work-arounds posted on the Internet do not work very well.
>
>But I finally found a usage scheme that seems to work fairly well for
>recursive grep.
>
>I have four versions of grep on my computer and only cygwin grep seems
>to work reasonably well, provided one __guesses__ at the right
>combination of arguments.  Here's what I've learned -- so you won't
>have to do such a horrendous amount of guessing.
>
>Here's a generic example of the usage of cygwin grep that works:
>
>grep  -r  --include="*.cc"  --include="*.cpp"  "Illegal number syntax" 
>*
>
>Here's the command & output in a cygwin bash shell in working directory
>/cygdrive/c/gnu/cln-1.1.11/src:
>
>$ grep  -r  --include="*.cc"  --include="*.cpp"  "Illegal number
>syntax"  *
>base/input/cl_read_err_bad.cc:  fprint(std::cerr, "Illegal number
>syntax: \"");
>base/input/cl_read_err_bad.cc--debug.cpp:       fprint(std::cerr,
>"Illegal numbe
>r syntax: \"");
>base/input/cl_read_err_bad.cc--original_now_in_effect.cpp:     
>fprint(std::cerr
>, "Illegal number syntax: \"");
>
>(Note that I labeled backup copies with a .cpp extension because "CLN
>make" in this area sweeps up any existing file with extension .cc for
>inclusion in the library.)
>
>Using the option "--directories=recurse" in place of "-r" produces the
>same output.
>
>But note that while "grep  -r  "Illegal number syntax"  *" searches
>_all_ files in the hierarchy and produces the output:
>
>base/input/cl_read_err_bad.cc:  fprint(std::cerr, "Illegal number
>syntax: \"");
>base/input/cl_read_err_bad.cc--debug.cpp:       fprint(std::cerr,
>"Illegal numbe
>r syntax: \"");
>base/input/cl_read_err_bad.cc--original_now_in_effect.cpp:     
>fprint(std::cerr
>, "Illegal number syntax: \"");
>Binary file cl_read_err_bad.o matches
>Binary file cl_read_err_bad.o--comment out for debugging.oxx matches
>
>, the more specific command "grep  -r  "Illegal number syntax"  *.cc"
>fails to produce the desired output, but instead we get:
>
>grep: *.cc: No such file or directory
>
>And, therefore to be expected, "grep  -r  "Illegal number syntax"  *.cc
>*.cpp" fails in the same way:
>
>grep: *.cc: No such file or directory
>grep: *.cpp: No such file or directory
>
>Of my four versions of grep, only cygwin grep has the "--include=..."
>option.  MinGW's msys grep does not have that option, and moreover,
>MinGW's msys grep has the same problem that cygwin grep has with the
>similar command:
>
>"c:/msys/1.0.8/bin/grep.exe"  -r  "Illegal number syntax"  *.cc
>
>Version information:  Executing the cygwin grep command "grep  -V"
>produces the output "grep (GNU grep) 2.5" along with (gnu) copyright
>and (non-) warranty information.  This grep was packaged in a cygwin
>setup.exe file that yielded an intermediate-expansion file (among many)
>with name "release\grep\grep-2.5-1.tar.bz2" along with a parallel
>intermediate-expansion file of
>"release\cygwin\cygwin-1.3.20-1.tar.bz2".
>
>Happy debugging!
>
>Richard Haney
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>_______________________________________________
>GiNaC-list mailing list
>GiNaC-list at ginac.de
>https://www.cebix.net/mailman/listinfo/ginac-list
>
>  
>


More information about the GiNaC-list mailing list