How can I get grep to display the filename before the matching lines in its output?
grep
No trick necessary.
grep --with-filename 'pattern' file
With line numbers:
grep -n --with-filename 'pattern' file