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

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

问题描述

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

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

推荐答案

尝试以下小技巧哄骗grep认为它正在处理多个文件,从而显示文件名:

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

还要获取行号:

grep -n 'pattern' file /dev/null

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

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