Compare 2 Text Files, and find equal words

Asked

Viewed 438 times

0

there is some tool that finds equal words in 2 different text files?

example:

arquivo1.txt

pedra
cavalo
torre
animal
fogo

arquivo2.txt

garoto
animal
festa
humano
fogo

outworking:

animal
fogo

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

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 pick up what will be fetched from the file. So it fetches all words from arquivo1.txt in the arquivo2.txt

  • Thank you for the answer, I got what I wanted, it’s not programming language at all, it’s just simple texts, but now I have another question, is there any way to remove a list of words from a text? > list_words: boy human text: boy animal party human fire > result: animal party fire

Browser other questions tagged

You are not signed in. Login or sign up in order to post.