Quote:
Originally Posted by
paragkalra
I have few of questions related to [GNU] Grep given below:
1. Like Perl, is it possible in Grep to negate characters in square brackets.
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.
Quote:
Originally Posted by
paragkalra
2. How do we match special characters in Grep?
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.
Quote:
Originally Posted by
paragkalra
3. 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:
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.