Wednesday, January 13, 2016

grep examples dot


using grep with a "." or dot in the search term (copy because of overactive editors)

http://stackoverflow.com/questions/10346816/using-grep-to-search-for-a-string-0-49

                     
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".










grep uses regexes; . means "any character" in a regex. If you want a literal string, use grep -F, fgrep, or escape the . to \..

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

No comments:

Post a Comment