Result the usual lines (resemblances) of 2 message submits (the reverse of diff)?

Diff is a wonderful device to present the adjustments in between 2 documents. Yet just how to present the resemblances of 2 message documents (while overlooking the distinctions)?

I.e. example input:

a:
Foo Bar
X
Hello
World
42

b:
Foo Baz
Hello
World
23

Quasi result (something similar to this) :

@@ 2,3
=Hello World

Simply arranging both documents and also making use of comm is not nearly enough, due to the fact that because instance the line details is shed.

0
2019-05-06 00:30:36
Source Share
Answers: 4
grep -Fxf file1 file2

-F suggests suit simple strings (not regexps), -x suggests just entire - line suits, -f methods take 'patterns' (i.e. lines) from the documents called as its argument

0
2019-05-10 18:09:52
Source

How around making use of diff, despite the fact that you do not desire a diff? Attempt this :

diff --unchanged-group-format='@@ %dn,%df 
  %<' --old-group-format='' --new-group-format='' \
  --changed-group-format='' a.txt b.txt

Below is what I get with your example information :

$ cat a.txt 
Foo Bar
X
Hello
World
42
$ cat b.txt 
Foo Baz
Hello
World
23
$ diff --unchanged-group-format='@@ %dn,%df
%<' --old-group-format='' --new-group-format='' \
  --changed-group-format='' a.txt b.txt
@@ 2,3
Hello
World
0
2019-05-08 12:59:14
Source

comm can be made use of. man comm for all the alternatives yet you'll intend to make use of comm -12 ... to show just lines that exist in both inputs.

As individuals have actually mentioned, you require to pass your input via sort first.

0
2019-05-08 12:32:08
Source

I do not assume there is a solitary command that does what you desire it to do. You can attempt to incorporate the result of diff with grep, however. If your message documents have none of the personalities |, <, >, the adhering to offers you rather valuable result :

$ diff --side-by-side a b | grep -n -v "[|<>]"
3:Hello                             Hello
4:World                             World
0
2019-05-08 12:28:10
Source