I want to print out the same lines in a.txt and b.txt. I think "grep -xf a.txt b.txt" meets my needs. But it doesn't work properly. My system environment is MacOs Mojave
[yangyue ~/tempDir]$ cat a.txt
123 abc
123 abc jjj
123
456
zzz
[yangyue ~/tempDir]$ cat b.txt
123 abc
123 abc jjj
123
456def
456
xyz
[yangyue ~/tempDir]$ grep --color=never -xf a.txt b.txt
123 abc
123
456
[yangyue ~/tempDir]$
the expected output in this case
123 abc
123 abc jjj
123
456
The encoding of these two files is the same. There is no space at the end of each line. I thinks the reason is "123 abc" is the prefix of "123 abc jjj" Then I did two tests.
test1
[yangyue ~/tempDir]$ cat 1.txt
a
ab
abc
[yangyue ~/tempDir]$ cat 2.txt
a
ab
abc
[yangyue ~/tempDir]$ grep --color=never -xf 1.txt 2.txt
a
[yangyue ~/tempDir]$
test2
[yangyue ~/tempDir]$ cat 3.txt
abc
ab
a
[yangyue ~/tempDir]$ cat 4.txt
abc
ab
a
[yangyue ~/tempDir]$ grep --color=never -xf 3.txt 4.txt
abc
ab
a
[yangyue ~/tempDir]$
Is this grep bug or is my usage wrong?