Hi All,
One of the text editors I use offers one to specify a grep pattern to do a multi-file search and I am not wrapping my head around proper RE patterns to accomplish using this.
There are so many rules!
Can anyone help with a specific example so I can try to understand better?
How would I write I want to find 'CP_', but NOT instances of 'CPLAT::CP_'?
-Jason
How would I write I want to find 'CP_', but NOT instances of 'CPLAT::CP_'?
What comes before 'CP_' when you want a match? Whitespace, other chars, is it just 'CPLAT::CP_' you don't want?
Anchor the search on that criteria, like a negated group before the 'CP_' or at least one of 'whitespace' for example...
Hi,
How would I write I want to find 'CP_', but NOT instances of 'CPLAT::CP_'?
What comes before 'CP_' when you want a match? Whitespace, other chars, is it just 'CPLAT::CP_' you don't want?
Yes whitespace always.
So what I am doing is a massive replace. So this grep will allow me to see how many instances still need to be replaced.
I am replacing CP_ with CPLAT::CP_ and when i execute the grep I want to ignore CPLAT:CP_ so I just see the CP_ that still need to be done.
-Jason
Yes whitespace always.
[root@dev ~]# echo " CP_" | egrep -e "\ CP_" CP_ [root@dev ~]# echo "CPLAT::CP_" | egrep -e "\ CP_" [root@dev ~]#
So what I am doing is a massive replace. So this grep will allow me to see how many instances still need to be replaced.
I am replacing CP_ with CPLAT::CP_ and when i execute the grep I want to ignore CPLAT:CP_ so I just see the CP_ that still need to be done.
Typo in that? You want to ignore " CPLAT::CP_" right? Depends on what tool you use and what std it follows, I don't even think you need to escape the "space".
Joseph L. Casale wrote:
Yes whitespace always.
[root@dev ~]# echo " CP_" | egrep -e "\ CP_" CP_ [root@dev ~]# echo "CPLAT::CP_" | egrep -e "\ CP_" [root@dev ~]#
So what I am doing is a massive replace. So this grep will allow me to see how many instances still need to be replaced.
I am replacing CP_ with CPLAT::CP_ and when i execute the grep I want to ignore CPLAT:CP_ so I just see the CP_ that still need to be done.
Typo in that? You want to ignore " CPLAT::CP_" right? Depends on what tool you use and what std it follows, I don't even think you need to escape the "space".
White space could be a tab. '[[:space:]]CP_' should work, but why not use sed and be done with it.
On Wed, Apr 07, 2010 at 04:04:53PM -0700, Slack-Moehrle wrote:
Yes whitespace always.
[..]
I am replacing CP_ with CPLAT::CP_ and when i execute the grep I want
Well, be clear. Are you replace "CP_" or " CP_". If the latter then it's a LOT easier; just search for " CP_" (grep ' CP_'). If the first then it's harder.
But sometimes it's easier to just not sweat the little stuff. Do two greps: grep CP_ | grep -v CPLAT::CP_
Not as efficiently, but adequate and easy.