You didn't post any example data of the 2 files so it hard to be specific to the level of code. I would be thinking of reading file 2 and making a hash table to use in the translation INATedIP => real device IP. Read through file 1 line by line, translate an IP address when you find one (probably with some form of regex), write lines to a new file. You will end up with a new 3 GB file with address as you want. Program will run about as fast as it takes to read the input file.