linux - grep 不匹配模式与 html 文件中的空格

标签 linux grep

我的 linux 服务器有一个包含所有 html 文件的文件夹。我正在尝试使用以下命令查找文件(名称和行号):

grep -rnw '/myfolder/' -e '</tr> <footer class="final-footer">' 

我知道几个包含这种模式的文件(在 </tr><footer class="final-footer"> 之间有一个严格的单个空格)。但是,grep 命令没有返回任何内容。

当我只搜索“<footer class="final-footer">”时'(没有 </tr> 和后面的单个空格)grep 正确返回。

 grep -rnw '/myfolder/' -e '<footer class="final-footer">' 

我尝试上面的命令只是为了检查我的 grep 语法是否正确。但我的具体要求是执行第一个命令。具体怎么做?

附加信息

其中一个文件中的模式样本是这样的:.... International, Inc.</td></tr> <footer class="final-footer"> ...

最佳答案

既然您知道要查找的确切字符串,那么您不妨使用 -F 选项。无需摆弄正则表达式。

grep -Fnr '</tr> <footer class="final-footer">'  myFolder

来自手册页:

-F, --fixed-strings
          Interpret PATTERN as a list of fixed strings (instead of regular expressions),
          separated by newlines, any of which is to be matched.

关于linux - grep 不匹配模式与 html 文件中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51826747/

相关文章:

shell - 使用 shell 命令提取版本

linux - jprobe do_execve 不适用于内核 4.1

C++:eclipse CDT 中的外部库

linux - 为什么我不能将文件夹上传到 Linux EC2 实例?

linux - 多个 grep 管道(包含+排除)导致不显示任何内容

linux - grep 特定字符串(多个)目录中的所有 Bean.java 文件(不区分大小写)

linux - 我怎样才能重新排序包含在 C 头文件中的内容?

bash - 在 grep 期间抑制 Openssl 输出

linux - 使用 jar 命令在 war 文件中包含隐藏文件

linux - 找不到 root.crt postgresql