Issue
I have a text file of words, one per line, called A.
I have another text file B.
How can I find all lines in B what have at least one of the words from A as a prefix?
I was hoping to be able to do this from the command line maybe using grep but any other command line solution would be great too.
For example, if A is
apple
bob
cheese
and B is
aple
bob123
ches
I would like the line bob123 to be returned.
Solution
One approach uses bash
's process substitution and sed
to add a regular expression beginning-of-line ^
anchor to each line of A, and then tells grep
to use it as a list of regular expressions to search for:
$ grep -f <(sed 's/^/^/' a.txt) b.txt
bob123
Answered By - Shawn Answer Checked By - Timothy Miller (WPSolving Admin)