[linux] Using grep to search for a string that has a dot in it

I am trying to search for a string 0.49 (with dot) using the command

grep -r "0.49" *

But what happening is that I am also getting unwanted results which contains the string such as 0449, 0949 etc,. The thing is linux considering dot(.) as any character and bringing out all the results. But I want to get the result only for "0.49".

This question is related to linux grep

The answer is


You can also use "[.]"

grep -r "0[.]49"

You can escape the dot and other special characters using \

eg. grep -r "0\.49"


Just escape the .

grep -r "0\.49"


Escape dot. Sample command will be.

grep '0\.00'

You can also search with -- option which basically ignores all the special characters and it won't be interpreted by grep.

$ cat foo |grep -- "0\.49"

There are so many answers here suggesting to escape the dot with \. but I have been running into this issue over and over again: \. gives me the same result as .

However, these two expressions work for me:

$ grep -r 0\\.49 *

And:

$ grep -r 0[.]49 *

I'm using a "normal" bash shell on Ubuntu and Archlinux.

Edit, or, according to comments:

$ grep -r '0\.49' *

Note, the single-quotes doing the difference here.


You need to escape the . as "0\.49".

A . is a regex meta-character to match any character(except newline). To match a literal period, you need to escape it.


grep -F -r '0.49' * treats 0.49 as a "fixed" string instead of a regular expression. This makes . lose its special meaning.