Thursday 26 May 2011

Exclude certain string pattern from grep

If we want to exclude a file while grep, we can --exclude=<filename>.
For excluding a directory we can use --exclude-dir=<directory name>.
But if we want to exclude a string pattern from grep how we will do it? For example, in my source code I want to see where all the define ART_BUILD is used. When I grepped it, I got ART_BUILD_NUM also in the grep result. I want exclude it from the result. How I will do it?

Well, I coudn't find direct solution for it. But, I got th result using the following command.
grep -nr <pattern to grep>  . | grep -v <pattern to be excluded>

I don't know whether a better solution is present or not. But served the purpose

No comments:

Post a Comment