我的 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/