I am trying to search for a string 0.49
(with dot) using the command
我正在使用这个命令搜索字符串0.49(带点)
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".
但是发生的是我也得到了不需要的结果它包含了字符串,比如0449 0949等等。问题是linux将dot(.)作为任何字符并显示所有结果。但我想要得到的结果只有“0。49”
8 个解决方案
#1
132
grep
uses regexes; .
means "any character" in a regex. If you want a literal string, use grep -F
, fgrep
, or escape the .
to \.
.
grep使用regex;。意思是regex中的“任何字符”。如果您想要一个文字字符串,请使用grep -F、fgrep或转义。\。
#2
29
grep -F -r '0.49' *
treats 0.49 as a "fixed" string instead of a regular expression. This makes .
lose its special meaning.
grep -F -r '0.49' *将0.49视为“固定”字符串,而不是正则表达式。这使得。失去其特殊意义。
#3
17
You need to escape the .
as "0\.49"
.
你需要逃离。为“0 \报”。
A .
is a regex meta-character to match any character(except newline). To match a literal period, you need to escape it.
一个。是一个regex元字符,用于匹配任何字符(除了换行)。要匹配一个文字周期,您需要转义它。
#4
5
Just escape the .
只是逃避。
grep -r "0\.49"
grep - r“0 \报”
#5
4
You can escape the dot and other special characters using \
您可以使用\来转义点和其他特殊字符
eg. grep -r "0\.49"
如。grep - r“0 \报”
#6
3
Escape dot. Sample command will be.
逃逸点。示例命令。
grep '0\.00'
#7
1
You can also use "[.]"
您还可以使用“[.]”
grep -r "0[.]49"
#8
1
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.
我在Ubuntu和Archlinux上使用“普通”bash shell。
#1
132
grep
uses regexes; .
means "any character" in a regex. If you want a literal string, use grep -F
, fgrep
, or escape the .
to \.
.
grep使用regex;。意思是regex中的“任何字符”。如果您想要一个文字字符串,请使用grep -F、fgrep或转义。\。
#2
29
grep -F -r '0.49' *
treats 0.49 as a "fixed" string instead of a regular expression. This makes .
lose its special meaning.
grep -F -r '0.49' *将0.49视为“固定”字符串,而不是正则表达式。这使得。失去其特殊意义。
#3
17
You need to escape the .
as "0\.49"
.
你需要逃离。为“0 \报”。
A .
is a regex meta-character to match any character(except newline). To match a literal period, you need to escape it.
一个。是一个regex元字符,用于匹配任何字符(除了换行)。要匹配一个文字周期,您需要转义它。
#4
5
Just escape the .
只是逃避。
grep -r "0\.49"
grep - r“0 \报”
#5
4
You can escape the dot and other special characters using \
您可以使用\来转义点和其他特殊字符
eg. grep -r "0\.49"
如。grep - r“0 \报”
#6
3
Escape dot. Sample command will be.
逃逸点。示例命令。
grep '0\.00'
#7
1
You can also use "[.]"
您还可以使用“[.]”
grep -r "0[.]49"
#8
1
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.
我在Ubuntu和Archlinux上使用“普通”bash shell。