Without any iteration with the --line-buffered grep option:
your_command | grep --line-buffered "your search"
Real life exemple with a Symfony PHP Framework router debug command ouput, to grep all "api" related routes:
php bin/console d:r | grep --line-buffered "api"