Search code examples
regexshellunixgrep

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


I have these:

$ cat a.tmp
ABB.log
ABB.log.122
ABB.log.123

I want to find a exact match of ABB.log.

But when I do:

$ grep -w ABB.log a.tmp
ABB.log
ABB.log.122
ABB.log.123

it shows all of the lines.

Can I get what I want using grep?


Solution

  • Simply specify the regexp anchors.

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