I need to find occurrences of "(+)" in my sql scripts, (i.e., Oracle outer join expressions). Realizing that "+", "(", and ")" are all special regex characters, I tried:
grep "\(\+\)" *
Now this does return occurrences of "(+)", but other lines as well. (Seemingly anything with open and close parens on the same line.) Recalling that parens are only special for extended grep, I tried:
grep "(\+)" * grep "(\\+)" *
Both of these returned only lines that contain "()". So assuming that "+" can't be escaped, I tried an old trick:
grep "([+])" *
That works. I cross-checked the result with a non-regex tool.
Question: Can someone explain what exactly is going on with the "+" character? Is there a less kludgy way to match on "(+)"?
(I am using the cygwin grep command.)
EDIT: Thanks for the solutions. -- And now I see that, per the GNU grep manual that Bruno referenced, "\+
" when used in a basic expression gives "+" its extended meaning, and therefore matches one-or-more "("s followed by a ")". And in my files that's always "()".