Use diff para encontrar diferenças na saída do comando two grep

2

É possível diff a saída de dois comandos grep ?

Atualmente estou procurando por arquivos, usando diferentes padrões de exclusão, e a saída é bem longa, então eu queria ver se meu novo padrão funcionava, ou a saída ainda é a mesma ..

É possível, de alguma forma, canalizar dois comandos grep para um diff ou algo assim?

grep --exclude=*{.dll, pdb} --ril "dql"
grep  --ril "dql"
    
por I am not Fat 02.04.2018 / 13:12

2 respostas

1

Em bash usando substituição de processo :

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

Como descrito em 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.
    
por 02.04.2018 / 13:19
0

Usando bash na mosca :

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 http://mywiki.wooledge.org/ProcessSubstitution.
Example: diff -u <(sort file1) <(sort file2)

Então:

diff <(grep --exclude=*{.dll, pdb} --ril "dql") <(grep  --ril "dql")
    
por 02.04.2018 / 13:20