test script: Improve speed by spawning grep only once, instead of once for every line

On my system it now completes the search in 2.9 seconds, whereas it used to take 10.5 minutes.