I'm having trouble correctly (and safely) executing the right regex searches with grep. I seem to be able to do what I want using ag
What I want to do in plain english:
Search my current directory (recursively?) for files that have lines containing both the words "nested" and "merge"
Successful attempt with ag:
$ ag --depth=2 -l "nested.*merge|merge.*nested" .
scratch.md
scratch.rb
Unsuccessful attempt with grep:
$ grep -elr 'nested.*merge|merge.*nested' .
grep: nested.*merge|merge.*nested: No such file or directory
grep: .: Is a directory
What am I missing? Also, could either approach be improved?
Thanks!
You can use
grep -lr 'nested.*merge\|merge.*nested'orgrep -Elr 'nested.*merge|merge.*nested'for your case.Besides, for the latter one,
Emean usingEREregular expression syntax, sincegrepwill useBREby default, where|will match character|and\|meanor.For more detail about
EREandBRE, you can read this article