我的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">
...
发布于 2018-08-14 07:21:38
由于您知道要查找的确切字符串,因此最好使用-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.
https://stackoverflow.com/questions/51826747
复制相似问题