Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Monday, September 10, 2012

ack: Exclude search directories via regex - from Stack Overflow

OK, the hints shown at the bottom worked pretty well for me.  I wanted to find a certain string in C source files, but not be distracted by compiled release directories named "rel*".  I guessed at which wildcard syntax ack supports, and I think I won:

(cd ~/Work/mse1/compiler; ack -G 'rel*' --invert-file-match --type=cc -- "builtin_object_size" )

YMMV.  No warranties expressed or implied.  Thank god for undocumented/lightly documented features...  ;-)
Cheers,
Connie
----------------------------------------
Stack Overflow:
"
How do I ignore specific directories via RegEx with ack?
I can use the --ignore-dir option, but this does not let me specify a RegEx. I want to be able to ignore any directory, which has the words test or tests or more complicated patterns in its name.
I also tried a negative lookbehind via
ack -G '(? pattern
but this does not work. It does not exclude the test directories.
share|edit

feedback

2 Answers


Use the undocumented option "--invert-file-match" (ack version on my system: 1.96):
$ ack pattern -G 'test|tests' --invert-file-match
Well, it is sort of documented:
$ ack --help|grep invert-v, --invert-match    Invert match: select non-matching lines--invert-file-match   Print/search handle files that do not match -g/-G.
It is not documented in its perldoc.
share|edit
 "
ack: Exclude specific directories from search via regex - Stack Overflow

'via Blog this'

More tools for searching source code


Tools that work with ack

AckMate

Users of TextMate, the programmer's editor for the Mac, can use the AckMate plugin by Trevor Squires:
TextMate users know just how slow its "Find in Project" can be with large source trees. That's why you need "ack-in-project" — a TextMate bundle that uses the super-speedy "ack" tool to search your code FAST. It gives you beautiful, clickable results just as fast as "ack" can find them. Check it out at: https://github.com/protocool/ackmate

vim integration

ack.vim provides an interface between ack and the vim text editor. For example, you can call :Ack foo, which will run ack and load ack's results into a vim buffer for manipulation and navigation.
ack.vim is available at the official vim website at http://www.vim.org/scripts/script.php?script_id=2572

Emacs integration

There are at least four different Emacs modes for supporting ack here at the Emacs Wiki: http://www.emacswiki.org/emacs/Ack
Note: Be careful of any solution that defaults you to using --all.

Other grep-like tools

There are many ways to search source code that are more flexible and tuned to programmers than straight grep. I suggest you take a look at some of these alternatives, for they may suit your needs better than ack. If you have any suggestions to add to this list, please let me know at andy@petdance.com.

Ag, the Silver Searcher

Geoff Greer says "Ag is like ack, but better. It’s fast. It’s damn fast. The only thing faster is stuff that builds indices beforehand, like Exuberant Ctags." Geoff has also created a fork of AckMate that uses Ag instead of ack.

grin

"A grep program configured the way I like it", written in Python by Robert Kern.

rak

A straight clone of ack, with some visual tweaks, written in Ruby by Daniel Lucraft.

glark

The biggest departure from ack, glark adds many more features like the ability to AND and OR your patterns. It's written in Ruby by Jeff Page.

Indexing tools

Sometimes when you're looking at a large codebase, it makes sense to see everything as a whole. An indexing tool may help you out.

ctags

ctags is a program almost as old as time itself. When run against a codebase, ctags indexes various elements of the code, such as variables and functions. This lets your editor or other tools use the tags index to jump quickly to that element.
The most common ctags implementation is Exuberant ctags: http://ctags.sourceforge.net/

Code Search

Russ Cox, the guy that wrote Google's CodeSearch engine, wrote an article about how it worked and released an implementation in Go.

OpenGrok

OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree.

cscope

Cscope is a developer's tool for browsing source code. Cscope was part of the official AT&T Unix distribution for many years, and has been used to manage projects involving 20 million lines of code. It also can integrate with vim and Emacs.

GNU GLOBAL

GNU GLOBAL is a source code tagging system that works the same way across diverse environments (emacs, vi, less, bash, web browser, etc). You can locate objects in source files and move there easily. It is similar to ctags or etags but is different from them at the point of independence of any editor.


More tools for searching source code

'via Blog this'

Thursday, September 6, 2012

unix - using ack to replace find/grep & address --exclude/--include syntax needs (do not grep through certain files) - from Stack Overflow

Please take a look at ack, which is designed for exactly these situations. Your example of
grep -ircl --exclude=*.{png,jpg} "foo=" *
is done with ack as
ack -icl "foo="
because ack never looks in binary files by default, and -r is on by default. And if you want only CPP and H files, then just do
ack -icl --cpp "foo="
share|improve this answer
Looks nice, will try the standalone Perl version next time, thanks. – Piskvor Oct 21 '08 at 14:39
2 
Good call, I can no longer live without ack. – Chance Nov 15 '10 at 21:21
1 
stackoverflow.com/questions/667471/… - This will allow you to get ack on windows, if that is where you are running grep from. – TamusJRoyce Dec 15 '10 at 16:58
Thank you for your feedback.

unix - grep --exclude/--include syntax (do not grep through certain files) - Stack Overflow

'via Blog this'