Silversearcher

From wikinotes
Revision as of 19:17, 23 November 2020 by Will (talk | contribs) (→‎Usage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The silver searcher is a file-searching module ag that searches more quickly than grep, and lets you perform multiline regex.

Install

sudo pacman -S the_silver_searcher  # arch
brew install the_silver_searcher    # macos

Usage

ag 'file.touch(\n\s.*)+'      # multiline search example

ag 'Foo(?!Bar)'               # lookahead/lookbehind!
ag '(?<=Foo)Bar'

ag --pager='less -Ri' search  # ag to pager

ag -G '.*\.rb$' foo             # search files matching '.*\.rb$' 

ag search \
  -l  `# print files only` \