Display filename before matching line

后端 未结 6 440
挽巷
挽巷 2020-11-30 16:28

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

6条回答
  •  一整个雨季
    2020-11-30 17:32

    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
    

提交回复
热议问题