在匹配行之前显示文件名(grep) [英] Display filename before matching line (grep)

查看:227
本文介绍了在匹配行之前显示文件名(grep)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得 grep 来在其输出中的匹配行之前显示文件名?

解决方案

尝试这个小技巧来哄 grep ,以为它处理多个文件,以便显示文件名:

  grep'pattern'file / dev / null 


$
$ b

  grep -n'pattern'file / dev / null 
$ b

也可以获得行号: $ b


How can I get grep to display the filename before the matching lines in its output?

解决方案

Try this little trick to coax grep into thinking it is dealing with multiple files, so that it displays the filename:

grep 'pattern' file /dev/null

To also get the line number:

grep -n 'pattern' file /dev/null

这篇关于在匹配行之前显示文件名(grep)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆