6. Search Punctuation Characters. The Punctuation characters for grep is to search line which will start from [! ” # $ % & ' ( ) * + , – . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~. ]
If you include special characters in patterns typed on the command line, escape them by enclosing them in single quotation marks to prevent inadvertent misinterpretation by the shell or command interpreter. To match a character that is special to grep –E, put a backslash ( \ ) in front of the character.
grep
uses regexes; .
means "any character" in a regex. If you want a literal string, use grep -F
, fgrep
, or escape the .
to \.
.
Don't forget to wrap your string in double quotes. Or else you should use \\.
So, your command would need to be:
grep -r "0\.49" *
or
grep -r 0\\.49 *
or
grep -Fr 0.49 *
grep -F -r '0.49' *
treats 0.49 as a "fixed" string instead of a regular expression. This makes .
lose its special meaning.
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.
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 can also use "[.]"
grep -r "0[.]49"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With