Use the -H
flag to show the filename header in the results.
Let’s return back to our handy test.txt
file with the following content:
sad
happy
awake
coffee
work
school
To see the filename header, run:
$ grep -H "awake" test.txt
test.txt:awake
This is the default when searching through multiple files. Let’s make a copy of test.txt
and run the grep command for both files.
$ cp test.txt test2.txt
$ grep "awake" test*.txt
test.txt:awake
test2.txt:awake
Use -h
if you explicitly don’t want to see the headers:
$ grep -h "awake test*.txt
awake
awake