1. Need to think how you are going to reproduce the main file. As you mentioned, that file contains all necessary data, so its might worth to make a copy of it, rather than build a new file line by line.
2. Then open the file with less data, and check, is entry present in a file "main_copy". If it is a case, label main_copy particular line with 1.
3. Maybe all lines need to label with zeros at start, and only matches override with 1's. Or find the matches, and then go thru the rest of the lines and label with zeros.
Pedro Rod wrote://if condition goes here, need help here
It doesn't seem that you have a clear understanding, what you want/have to do.
I'd suggest you to write down the clear steps on a plain paper, what has to be done. Then you would find it much easier to translate it to code.