I would have to use a scripting language to get the desired result fastest. I think I would write a regex that could be used for the needles by a regex match function like re.match('INV [0-9]* ') that is run across each line and line no's and invoice numbers are stored in a dictionary.
Run the program again against the haystack and generate a dictionary of line number, invoice number.
A function that lists the line number from the needles string and haystack string and outputs a tuple of the form {line no in needles file, line number in haystack file} then simple iterate the list of tuple pairs and concatenate those respective lines and print the result for all the matches in the dictionary.
Let me know where you're stuck if you don't find a simpler approach. I don't know how to do this with just regex or some other one liner approach !