Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 *

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...