in reply to how to comment the lines if found a match

So what have you tried so far?

My idea: read the first file, build a regex from all lines (by joining the lines with |), then read the second file, and prepend a # to all lines which match the regex.

(It's easier if you first produce the correct output instead of editing the file in-place).