Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Created July 30, 2021 02:19
Show Gist options
  • Save rattrayalex/8866071bab0c2db5f5011bfec4e6039a to your computer and use it in GitHub Desktop.
Save rattrayalex/8866071bab0c2db5f5011bfec4e6039a to your computer and use it in GitHub Desktop.
Ripgrep ignore/exclude files that match a certain string

Say you want to search for a certain string, but exclude files which match another pattern.

PATTERN_TO_EXCLUDE="bad.+words"
DIR_TO_SEARCH=foo/bar
PATTERN_TO_FIND="good.+good"

rg $PATTERN_TO_FIND --stats $(rg $PATTERN_TO_EXCLUDE --files-without-match $DIR_TO_SEARCH)

A files which does contain "good regex" will be matched, unless it also contains "bad regex".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment