I think I understand the basic point, but it would help a lot more if we could see the actual code
you're using, rather than just a vague description of what it does. The best solutions to use in cases like this often depend on the exact context of the problem.
As Nylex pointed out, at the very least you can store the grep results in a variable, and test that in order to determine what to print. You can also often use shell built-in features
extract substrings if necessary.
line="$( grep "string" inputfile )"
if [[ "$line" ]]; then
<extract and print substring>
But there may be even better options, depending on just what you need to do.