Celeb Glow
updates | February 28, 2026

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

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"
3

2 Answers

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.
5

Using on the fly :

diff <(grep pattern file) <(grep another_pattern file)

Process Substitution: <(command) or >(command) is replaced by a FIFO or /dev/fd/* entry. Basically shorthand for setting up a named pipe. See .
Example: diff -u <(sort file1) <(sort file2)

So :

diff <(grep --exclude=*{.dll, pdb} --ril "dql") <(grep --ril "dql")
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy