I want to grep file A for every phrase in file B, where a phrase is a string of words of length X. Ideally, it would be an approximate grep, like agrep. Is there a way to do that using command-line tools?
Can I grep two files against each other?
arch linux;grep
With zsh, you could try something like:x=3B_words=($(<B))A_words=($(<A))A=$A_wordssetopt extendedglobfor ((i = 1; i<=$#B_words - x + 1; i++)) {  phrase=$B_words[i,i+x-1]  [[  $A  = (#a2)* $phrase * ]] && printf '%s\n' $phrase}Which should give you the sequences of 3 words of file B that are also found in file A (allowing 2 errors with (#a2)).For instance, if A is your question and B is the sentence above, I get:of 3 words3 words ofin file AOr if you want to see what was matched in file A:for ((i = 1; i<=$#B_words - x + 1; i++)) {  phrase=$B_words[i,i+x-1]  [[  $A  = (#a2)(#b)* ($phrase) * ]] &&    printf '%s\n' $phrase ($match[1])}which gives:of 3 words (of words)3 words of (words of)in file A (in file B,)words here are defined as sequences of non-IFS characters which with the default value of $IFS is any character other than space, tab, newline and nul.