forget O(n) etc. the original poster was slurping the whole files into memory, which was the cause of the slowness. grep will match the number in the 3 files (several megs total) in about a second....which surely meets the criteria for response time. the poster is a beginner, so would be best for them to have a one liner with a 1 second response time..rather than complicated code with at best 0.5 second response time.
the hardest line to type correctly is: stty erase ^H