grep -l 和 grep -ln
根据 grep 手册,
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
grep -l
,这似乎很好,因为当找到匹配项时,会回显包含匹配项的文件名。
但是,当我执行 grep -ln 时,grep 会回显出现的每一行。
grep -l 是否真的意味着在找到第一次匹配时停止并停止扫描,而 grep -ln 会忽略 -l > 旗帜?
according to the manual for grep,
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
grep -l
, this seems fine in that when a match is found, the file name containing the match is echoed.
However when i do a grep -ln
, grep echoes every line of the occurrence.
Does grep -l
really mean to stop when the first occurrence of the match is found and stop scanning, while grep -ln
will ignore the -l
flag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些选项是不兼容的。如果要显示每个文件中第一个匹配项(并且仅第一个匹配项)的行号,请使用 grep -Hnm 1 。
Those options are incompatible. Use
grep -Hnm 1
if you want to display the line number of the first match (and only the first match) in each file.