Functionally (in terms of output), these two values ββare the same. The first of them actually creates a separate cat process, which simply sends the contents of the file to standard output, which is displayed on standard grep input, because the shell has connected two to the channel.
In this sense, grep regex <filename also equivalent, but with one smaller process.
If you start to see a difference in options when additional information (file names) is used by grep , for example:
grep -n regex filename1 filename2
The difference between this and:
cat filename1 filename2 | grep -n regex
lies in the fact that the former knows about individual files, while the latter sees it as a single file (without a name).
So far, the first one can give you:
filename1:7:line with regex in 10-line file filename2:2:another regex line
the latter will be more like:
7:line with regex in 10-line file 12:another regex line
Another executable that acts differently if it knows the file names is wc , a word counter program:
$ cat qq.in 1 2 3 $ wc -l qq.in
paxdiablo
source share