更新时间:2023-12-03 16:48:52
这里的问题是正常的 grep 不匹配多行.所以,我会安装 pcregrep
并尝试以下命令:
The problem here is normal grep doesn't match multiple lines. So, I would install pcregrep
and try the following command:
pcregrep -rMl '?>[s
]+z' *
这将使用 PCRE 多行匹配(-M
部分)匹配文件夹和子文件夹(-r
部分)中的所有文件,并且只列出它们的文件名(-l
部分).
This will match all files in the folder and subfolders (the -r
part) using PCRE multiline match (the -M
part), and only list their filenames (the -l
part).
至于模式,匹配 ?>
后跟 1 个或多个空格或换行符,后跟文件结尾 z
.但是我发现,当我在我的文件夹中运行它时,许多 PHP 文件实际上以一个换行符结尾.因此,您可以将该正则表达式更新为 '?>[s
]+
z'
以匹配单个
上方带有空格的文件> 字符终止符.
As for the pattern, well that matches ?>
followed by 1 or more whitespace or newline characters, followed by the end of the file z
. I found though, when I ran this on my folder, many of the PHP files do in fact end with a single newline. So you can update that regex to be '?>[s
]+
z'
to match files with whitespace over and above the single
character terminator.
最后,如果您需要检查其确切的字符序列结尾,您始终可以使用 od -c filename
打印文件的明确表示.
Lastly, you can always use od -c filename
to print unambiguous representation of the file if you need to check its exact character sequence ending.