I have few of questions related to Grep given below: 1. Like Perl, is it possible in Grep to negate characters in square brackets. For example in Perl, if '^' is used inside '' then it acts as a negation characters. Can same be achieved through Grep's regular expression.
How do we match special characters in Grep?
I have following file:
cat /tmp/pk.ldif
My aim is to find only those files starting with dn, and containing the string 'ou=' exactly 3 times. Can anybody why this is not working:
Yes, and this is true of probably all regular expressions. The syntax is nearly identical across all platforms; however there may be variations on handling special characters such as the dash (-), the brackets ([ and ]) and the caret (^) itself. Character classes, such as [[:digit:]] work too, but there are slight differences.
You escape them with the backslash (\), as you usually do in perl. The problem is that in the normal grep mode, some special characters ^ $ . * are always on, and some ( ) ? + { } are on when you escape them. However, if you use "egrep" (or -E with GNU grep), you get the situation where all special characters are "magical" unless you escape them.
Yeah, because grep treats each separate line as a new search space. So the whole idea of matching a set of 3 lines with (atom){3} won't work, period. So grep is not the right tool here unless you first use tr or sed to translate all newlines into some other caracter (x1B for instance). Then you need to use egrep or grep -E and your regexp *might* work.