Refined to more generically handle grep output.