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

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