Use diff to find difference in the output of two grep command

bashdiff()grepterminal

Is it possible to diff the output of two grep commands?

I am currently searching for files, using different exclude patterns, and the output it pretty long, so i wanted to see if my new pattern worked, or the output is still the same..

Is it possible to somehow pipe two grep command into a diff or something like that?

grep --exclude=*{.dll, pdb} --ril "dql"
grep  --ril "dql"

Best Answer

In bash using process substitution:

$ echo a > FILE
$ echo b > FILE1
$ diff <(grep a *) <(grep b *)
1c1
< FILE:a
---
> FILE1:b

As describen in man bash:

   Process Substitution
   Process substitution is supported on systems that support named
   pipes (FIFOs) or the /dev/fd method of naming open files.  It
   takes the form of <(list) or >(list).  The process list is run
   with its input or output connected to a FIFO or some file in
   /dev/fd.  The name of this file is passed as an argument to the
   current command as the result of the expansion.  If the >(list)
   form is used, writing to the file will provide input for list.
   If the <(list) form is used, the file passed as an argument
   should be read to obtain the output of list.

   When available, process substitution is performed
   simultaneously with parameter and variable expansion,
   command substitution, and arithmetic expansion.
Related Question