0

I have two text files with different outputs. I would like to find the common lines by comparing these two files. This is just an example but I'm finding common values.

file1.txt contains:

12XVGAS4RJQ3wZopCc7bvjRSjHBrRR9bmw
12XVGsHANa9s4Szkmk73nTC5vTJHdFfx7w
12XVGwB6c72mmQCqEwCQtbuKmStw5RqW3X
12XVHEx5yorWhjxzFHMBW1ynPVCNwWfiDR
19vLAtK2PivKYB1ZT1J7dykw3rYga4SoVu

file2.txt contains

1PXT4TSriFBPvwSnC4xZYw33xYq93vKWJA
1PXtc18rtLYEMDpFpXHTeKRjKxor4HMa1m
1PxTPT8Cc2zd2jub8XQ2qU2NUY27Z37J7G
19vLAtK2PivKYB1ZT1J7dykw3rYga4SoVu

Here are the commands I have tried so far to get 19vLAtK2PivKYB1ZT1J7dykw3rYga4SoVu:

  1. comm -12 <(sort file1.txt) <(sort file2.txt)
  2. grep -wFf file1.txt file2.txt

I am baffled as to why there is no output but if I try to manually cat and grep both file1.txt and file2.txt I can see the result so this address does exist in both files.

cat file1.txt | grep 19vLAtK2PivKYB1ZT1J7dykw3rYga4SoVu

ChaosX
  • 17
  • 4
  • 1
    Sure one of your files isn't in DOS format? Different newline types would explain this – Charles Duffy Sep 08 '22 at 18:03
  • Note that the way you're using grep isn't requiring an exact full line match; it'll still match even with trailing whitespace, hidden characters, etc. Consider using `hexdump -C`, `cat -A`, or similar tools to view nonprintable data. – Charles Duffy Sep 08 '22 at 18:04
  • Oh you are right one of my text file was in DOS format. Thank you! – ChaosX Sep 08 '22 at 18:27

0 Answers0