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
To also get the line number:
grep -n 'pattern' file /dev/null
2.1m questions
2.1m answers
60 comments
57.0k users