Please back up a few steps. Can you state what you want your code to do, in ordinary language? You say what your inputs are, what code you tried, but your description of what you want to accomplish is all muddled up with what you tried, and the end product doesn't make much sense, at least to me.
Are you:
Trying to compare two files, and if they have an identical line, print the lines from the second file surrounding that line?
Searching a number of texts for a particular string from the command line, and if the string appears in one of the texts, print the first line of the text along with the lines surrounding the match?