问题描述
我正在尝试使用命令搜索字符串 0.49
(带点)
I am trying to search for a string 0.49
(with dot) using the command
grep -r "0.49" *
但是发生的事情是我也得到了不需要的结果,其中包含诸如 0449
、0949
等字符串.事情是 linux 将 dot(.) 视为任何字符并带出所有结果.但我只想得到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
使用正则表达式;.
在正则表达式中表示任何字符".如果您需要文字字符串,请使用 grep -F
、fgrep
,或将 .
转义为 .
.
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" *
或
grep -r 0\.49 *
或
grep -Fr 0.49 *
这篇关于使用 grep 搜索包含点的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!