fobiss
fobiss

Reputation: 69

text comparison with grep (a.txt contians words, b.txt contains strings, if a string from b.txt contains words form a -> output)

Simple text comparison: a.txt contains words, b.txt contains strings, if a string from b.txt contains a word or words from a.txt -> c.txt (the string from b.txt, not the word from a.txt)

a.txt

CREDIT

b.txt

CREDITUNION

Sourcecode:

grep -F -o -f b.txt a.txt | sort | uniq > c.txt

Since 'CREDITUNION' contains the word 'CREDIT' in c.txt 'CREDITUNION' have to show up... But its not...

Can you please tell me why?

Upvotes: 1

Views: 151

Answers (1)

devnull
devnull

Reputation: 123608

You seem to have flipped the file containing the pattern with the input file.

Specify the file containing the words as an argument to -f, and the file containing the strings as the input file to grep. Moreover, remove the -o option else you would see the words in the output and not the strings, e.g. you'd see CREDIT instead of CREDITUNION:

grep -F -f a.txt b.txt | sort | uniq > c.txt

Upvotes: 1

Related Questions