Verwenden Sie diff, um den Unterschied in der Ausgabe von zwei grep-Befehlen zu ermitteln

784
I am not Fat

Kann diffich zwei grepBefehle ausgeben ?

Ich suche momentan nach Dateien, benutze verschiedene Ausschlussmuster und die Ausgabe ist ziemlich lang, also wollte ich sehen, ob mein neues Muster funktioniert oder die Ausgabe immer noch gleich ist.

Ist es möglich, zwei grepBefehle irgendwie in ein diffoder ähnliches zu pfeifen?

grep --exclude=*{.dll, pdb} --ril "dql" grep --ril "dql" 
2
Leiten Sie die "grep" -Ausgabe in 2 Dateien um und "diff" die Dateien. DavidPostill vor 6 Jahren 0
Bitte lesen Sie [MCVE] (https://stackoverflow.com/help/mcve) Gilles Quenot vor 6 Jahren 0
@DavidPostill Das war meine ursprüngliche Idee, aber ich wollte wissen, ob es einen ordentlicheren "Trick" gab, als temporäre Dateien zu erstellen, und "diff" diese. I am not Fat vor 6 Jahren 0

2 Antworten auf die Frage

2
Arkadiusz Drabczyk

Bei bashVerwendung von Prozess Substitution :

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

Wie beschrieben 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. 
der tldp bash guide ist veraltet und in manchen fällen einfach falsch. Gilles Quenot vor 6 Jahren 0
Es ist nur das erste Ergebnis, das aufgetaucht ist. Ich habe auch einen Auszug aus "man bash" hinzugefügt. Arkadiusz Drabczyk vor 6 Jahren 0
Bitte verlinke niemals tldp. Es ist nicht so, weil es das erste Ihrer Suche ist, das am relevantesten ist. http://mywiki.wooledge.org/ProcessSubstitution ist wirklich ein besserer Ort Gilles Quenot vor 6 Jahren 0
Könnten Sie ein Beispiel geben, wenn "TLDP" falsch oder veraltet ist? Ich habe es nie wirklich zum Lernen benutzt, aber es könnte trotzdem nützlich sein, es zu wissen. Arkadiusz Drabczyk vor 6 Jahren 0
Fragen Sie Greybot `! Tldp` auf irc` # bash @ irc.freenode.org` und die Jungs dahinter. Wenn Sie gute Ressourcen benötigen: FAQ: http://mywiki.wooledge.org/BashFAQ | Anleitung: http://mywiki.wooledge.org/BashGuide | Ref: http://gnu.org/s/bash/manual | http://wiki.bash-hackers.org/ | http://mywiki.wooledge.org/Quotes | Überprüfen Sie Ihr Skript: http://www.shellcheck.net/ Gilles Quenot vor 6 Jahren 0
0
Gilles Quenot

Mit on the fly :

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

Prozessersetzung: <(command)oder >(command)wird durch einen FIFO- oder / dev / fd / * -Eintrag ersetzt. Kurz gesagt, um eine Named Pipe einzurichten. Siehe http://mywiki.wooledge.org/ProcessSubstitution .
Beispiel:diff -u <(sort file1) <(sort file2)

So :

diff <(grep --exclude=*{.dll, pdb} --ril "dql") <(grep --ril "dql") 
hmmm ... Ich bekomme die Fehlermeldung `diff: zusätzlicher Operand` / dev / fd / 61 '' I am not Fat vor 6 Jahren 0
-bash: 0: mehrdeutige Weiterleitung I am not Fat vor 6 Jahren 0
Ich glaube, du hast einen Tippfehler gemacht Gilles Quenot vor 6 Jahren 0
nicht sicher, wo aber .. `diff <(grep --exclude = *. -ril "del".) <(grep --exclude = *. -ril "del".) ` I am not Fat vor 6 Jahren 0