This answer is a combination of @danvoronov's initial post, and @waltinator's solution to getting the unused keys, with improvements to both.
I have about 60 lines of Bash and awk which construct test files using random selections from English language sets in the Princeton CS50 course material. I also have 30 lines of Bash and awk which solve this problem in a single process. This needs performance improvement so I will not as yet post it.
My script and the one posted below produce identical results. For reference and checking purposes, each output text is preceded by the line number in the original file. The test files consist of 15000 shorter records in file1 (12000 that match file2 and 3000 that do not, average length 92 chars), and 20000 full lines in file2 (average length 129 chars).
The keys are taken from a random selection of the larger records, taking a random number of words (but at least four) starting from a random word in the line.
Note that a single key can match multiple records. We do not attempt to enforce one-on-one pairing.
The posted script below runs on that data volume in about 1m:30s (my awk in 5m:45s).
The data from file1 is not likely to be valid regular expressions, so the -F option has to be used in grep. If plain text is treated as an RE, many characters like * + . will match unexpectedly, and others like ( ) [ ] | will throw errors. -F can also be much faster (I found a 600x improvement -- I want to know what that algorithm is!).
The grep for unused keys just uses a -q option, and the status shows whether a match occurred. This saves two processes (a subshell and a wc -l for each line in file1), and on average it also halves the data read, because it exits on first match rather than reading the whole file.
#! /bin/bash
grep -n -w -F -f file1.txt file2.txt > file3.txt
while read -r Key; do
(( ++Fnr ))
grep -q -w -F -- "$Key" file2.txt || printf '%d:%s\n' "${Fnr}" "$Key"
done < file1.txt > file4.txt
As some of the initial questions are unanswered (whether the data is in fields, whether whitespace matters, any data volumes), comments are invited.
diff
commandcomm
diff
andcomm
both require the two files be similarly formatted and lines containing the same things. As I said the files are different in that file2 has strings from file1 but the all lines have more text than just those strings.