Compare 2 Text Files, and find equal words [closed]

0

Is there a tool that finds words in 2 different text files?

example:

file1.txt

pedra
cavalo
torre
animal
fogo

file2.txt

garoto
animal
festa
humano
fogo

result:

animal
fogo

It is not necessary to be 2 .txt files exactly, but only 2 different texts.

    
asked by anonymous 13.07.2018 / 14:23

1 answer

2

As you have not specified the language, I will offer the simplest solution in bash.

$ grep -f arquivo1.txt arquivo2.txt
> animal
> fogo

The -f parameter tells pro grep to get what will be fetched from the file. So it will fetch all words from arquivo1.txt into arquivo2.txt

    
13.07.2018 / 14:38