简体   繁体   English

如何使用grep和regex查找双引号字符串?

[英]How to find a double quoted string using grep and regex?

I'm trying to find all the occurrences of the string "5.1" in all files under a certain directory. 我正在尝试查找某个目录下所有文件中所有出现的字符串“ 5.1”。 I've tried using the following command but it finds none: 我尝试使用以下命令,但找不到任何命令:

#grep -Re[5]+\.+[1] .

What am I doing wrong? 我究竟做错了什么?

您不需要e正则表达式,因此fgrep构造起来更简单,执行起来也更快

fgrep -R '"5.1"' .

Your expression doesn't make sense to me. 你的表情对我没有意义。 It seems like you're looking for: 似乎您在寻找:

grep -R '5\.1' .

Or if you want to include the " characters: 或者,如果您想包含"字符:

grep -R '"5\.1"' .

But I don't see anything related to those in your original post, so it's hard to say. 但是我在您的原始帖子中没有看到与之相关的任何内容,因此很难说。

Looking for a fixed string recursively would be 递归查找固定字符串将是

grep -fR '"5.1"' .

(if you really meant including the double quotes). (如果您确实要包括双引号)。

Note that the -R option is not POSIX, so may not be available. 请注意, -R选项不是POSIX,因此可能不可用。 In that case, the portable solution is 在这种情况下,便携式解决方案是

find . -type f | xargs grep -f '"5.1"'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM