Grep

From Colettapedia
Jump to navigation Jump to search

POSIX grep

  • grep -r -l "pattern" .
    • -r = recurse
    • -l = names only
    • pattern then the starting point
  • grep -v, --invert-match = select non-matching lines (a NOT operation!)

ripgrep

  • rg searchstring --iglob '!*.ipynb' - exclude any file whose filename matches the glob pattern (using single quotes)
    • rg title --iglob '!*.ipynb' --iglob '!*.json' - multiple patterns
  • -l, --files-with-matches - Print only the paths with at least one match and suppress match contents.