Replace printf | grep with a case