How to make grep only match if the entire line matches? How to make grep only match if the entire line matches? unix unix

How to make grep only match if the entire line matches?


grep -Fx ABB.log a.tmp

From the grep man page:

-F, --fixed-strings
Interpret PATTERN as a (list of) fixed strings
-x, --line-regexp
Select only those matches that exactly match the whole line.


Simply specify the regexp anchors.

grep '^ABB\.log$' a.tmp


Here is what I do, though using anchors is the best way:

grep -w "ABB.log " a.tmp