24

I have certain CSS files of fileName *-c.css and *-gen.css which I want to ignore from ack-grep searches.

I see that --type-set=TYPENAME=.extension does not accept regex filters like *-c.css, any idea of how to get around this problem ?

2 Answers2

44

I came across ack-grep 2.0 which provides --ignore-file option based on regex pattern as below and it worked after adding it to ~/.ackrc.

--ignore-file=match:-c.js
--ignore-file=match:-gen.js
--ignore-file=match:-c.css
--ignore-file=match:-gen.css
  • 17
    for exact file names: `--ignore-file=is:` - for ctags file: `--ignore-file=is:tags` – mMontu Oct 24 '13 at 12:18
  • Filters for different uses can be found on http://beyondgrep.com/documentation/ack-2.10-man.html#defining_your_own_types – mMontu Oct 24 '13 at 12:24
  • 5
    For all the too-fast readers finding this: Note that the '-' in the match string above is not saying "remove c.js files" - the '-' is part of the file name in the original question! – Ross R Jan 23 '17 at 14:16
1

Use a regular expression to filter those files you want to search.

ack -G '(?<!-c)(?<!-gen)\.css$' expression_to_search

It uses the perl flavour. I do a negative look-behind to skip those that contain -c or -gen just before the extension.

Birei
  • 35,723
  • 2
  • 77
  • 82
  • For those reading this in 2019 or beyond, ack 3.x doesn't support the `-G` option. You have to use `ack -g pattern | ack -x expression_to_search`. – Andy Lester Sep 04 '19 at 04:35