I'm looking for a way to display the filename when using this command:
cat *.tcp | grep "tcp" | grep "open" | sort | uniq
Is there a way to do it?
grep tcp *.tcp | grep open | sort -u
Giving multiple filenames to grep will, by default, cause grep to prefix the matching output lines with the filename(s) they matched in. The only other change I made was to combine sort | uniq into sort -u (and to remove the quotes that are unnecessary here).
open: maybe that's not an issue in this particular application - otherwise perhaps consider replacing the second grep by an awk e.g. awk -F: '$2 ~ /open/'?
grep -H 'tcp'
-H, --with-filename Print the file name for each match. This is the default when there is more than one file to search.