I have two files A.txt and B.txt containing two lists respectively as shown bellow.
File A.txt
hello
hi
ko
File B.txt
fine
No
And how
why
Now I want to check presence of any of these words (from A.txt AND B.txt) in a line in another file C.txt.
I am using the grep command
grep -iof A.txt C.txt| grep B.txt
C.txt contains sentences containing words from A.txt and B.txt
Hello I am fine
I am not fine
why ko is and how?
doesn't show any output
So, now I want if any word from A.txt and B.txt present simultaneously in one sentence it should show the output as
Hello fine
why ko and how
To print only the matching words from both files if they occur simultaneously in C.txt, instead of printing the whole line from C.txt