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:bAs 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 bash 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