Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i exclude comments from ack results?

Hi im new to ack (actually started half an hour ago). Im impressed by the quality of the search results.

But in my source files there are a lot of comments and if i search for a class/function-name i get about 20 results with commented lines and 2 with the actual code.

Is there a way to exclude text after // and # or between /* */?

like image 397
Shylux Avatar asked Sep 19 '13 09:09

Shylux


1 Answers

You could skip single line comments with something like this;

# ignore matches after //
ack '^[^//]*word'
# ignore matches after #
ack '^[^#]*word'

If you are using ag instead, remember that it does multi-line matches:

# ignore matches after //
ag '^[^\n\r//]*word'
# ignore matches after #
ag '^[^\n\r#]*word'
like image 75
sina Avatar answered Oct 21 '22 11:10

sina