0

I got a Grep that is killing me

Let's suppose i got the a file (file.xml) with the two below entries:

  • pos_ADF_datasource-1450-jdbc.xml
  • datasource-1450-jdbc.xml

Now If i run the below grep:

grep -E '(ADF)' file.txt

I got the below output:

pos_ADF_datasource-1450-jdbc.xml

Now i want to exclude ADF to get the other entry, it should be easy, but i tried it all and I'm unable to let it works:

grep -E '(?<!ADF)' file.txt

I tried many but i'm sure there is something i'm not considering that is making my expression not working...

I need and want to use the -E, i know it works not using the extended regex!

Please guys me light me!

RESOLVED:

Thanks Wiktor for the below consideration:

ERE POSIX does not support lookarounds. Even if you use -P excluding 'ADF' it will just match any position that is not preceded with ADF

You cannot check with an ERE regex if a string does not contain a pattern. Only if it is not equal, does not start/end with a pattern. You may only do it with a PCRE regex. grep -P '^(?!.*ADF)' file.txt

Then i figured it out with grep -Pe:

grep -Pe "^((?!.*ADF).)*-jdbc.xml$" file.xml
Community
  • 1
  • 1
ivoruJavaBoy
  • 1,307
  • 2
  • 19
  • 39

0 Answers0