Well yes, but what are the chances the files are sorted? You could also assume they aren't sorted, make a pass through both to find out which lines match between the two, pass through one again to retrieve just those lines, and pass through the other to match. This would only require storing lines with a key match in memory instead of an entire file.