The grep command uses the Boyer Moore string search algorithm. This algorithm is famous for being unbelievably efficient.