I have a text file containing a list of strings, for example a.txt
one
two
three
I also have another text file containing a list of strings, for example b.txt
threetwo
onetwothree
zero
twozero
What I wish to do is compare the two and find whether any of the fields inside b.txt
contain fields from a.txt
Example of output in this case would be,
threetwo > two, three
onetwothree > one, two, three
twozero > two
If my explanation wasn't explanatory enough then I have this written in C# which will produce my expectations.
List<string> allElements = new List<string> { "one", "two", "three" };
string str = "onetwothree";
var containingElements = allElements.Where(element => str.Contains(element));
foreach(string element in containingElements)
{
Console.WriteLine(element);
}
you can run the above code on dotnetfiddle.net
I would prefer this to be achieved using awk, any help would be appreciated :).
grep -f a.txt b.txt
finds whether any of the fields inside b.txt contain fields from a.txt. – berndbausch Jan 22 '21 at 07:06