in reply to Exit a program if there are any matching lines?
Run cgrep, my grep clone, with the -q or -l or -L option, any of which makes the program stop reading when a matching line is found. Then, look at the source if that's what you want.