cat 和 grep 匹配的文件名和行号
我的代码
$ *.php | grep google
如何打印每个匹配项旁边的文件名和行号?
My code
$ *.php | grep google
How can I print the filenames and linenumbers next to each match?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果你想跨越多个目录:(
如注释中所述,如果 xargs 只出现一个剩余文件,-H 很有用)
if you want to span many directories:
(as explained in comments, -H is useful if xargs comes up with only one remaining file)
你不应该这样做
这意味着“运行第一个 PHP 程序,将其余通配符的名称作为参数,然后在输出上运行 grep”。
它应该是:
-n
标志告诉它执行行号,-H
标志告诉它显示文件名,即使只有文件。 如果正在搜索多个文件,Grep 将默认显示文件名,但您可能希望确保输出一致,无论有多少个匹配文件。You shouldn't be doing
That means "run the first PHP program, with the name of the rest wildcarded as parameters, and then run grep on the output".
It should be:
The
-n
flag tells it to do line numbers, and the-H
flag tells it to display the filename even if there's only file. Grep will default to showing the filenames if there are multiple files being searched, but you probably want to make sure the output is consistent regardless of how many matching files there are.请查看 http://betterthangrep.com 上的 ack。 您正在尝试的 ack 的等效项是:
Please take a look at ack at http://betterthangrep.com. The equivalent in ack of what you're trying is:
使用“man grep”查看其他功能。
Use "man grep" to see other features.