📝 Edit on GitHub
Match types
Basic
Find word.
grep foo PATH
Exact match
grep -w 'foo' bar.txt
Invert match
grep -v 'foo' bar.txt
That will invert the match on each line.
If you want to want to find entire files which do not match a pattern, use:
grep -L 'foo' bar.txt baz.txt
Regex
There are three types of regex:
- basic (BRE)
- extended (ERE)
- perl (PCRE)
The basic one supports matching such as these:
grep '\sfoo' PATH
Blank line
grep '^$' filename