Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Grep with regex containing one string but not the other

$
0
0
Hi to you all,

I'm just struggling with a regex problem and I'm pretty sure that I'm missing sth obvious... :confused:

I need a regex to feed my grep in order to find lines that contain one string but not the other.

Here's the data example:

Code:

2015-04-08 19:04:55,926|xxxxxxxxxx|          |foobar|          |INFO |REQUEST|UserID1:42 | yeah
2015-04-08 19:04:56,157|yyyyyyyyyy|          |foobuzz|          |INFO |REQUEST|UserID1:23 | ohnooo

I want all lines with "UserID1" not containing "foobuzz". I tried this one:

Code:

LC_ALL=C grep -P '(?!foobuzz).*UserID1.*' example.txt
But it gives me both lines. (I have the "LC_ALL=C" workaround from a RedHat article, otherwise I get a core dump for free. ;-) )

What's wrong with me, uhm, with the regex?

And yes, it should be grep because the new regex will be part of an existing regex file which is used by a script in order to grep some gigabytes of data multiple times a day. I don't know if it would be faster with awk or sth like this. Any advice is appreciated!

I will get back to you tomorrow - it's late, I'm the last one in the office, sun is gone... ;-)

Best regards

Stephan

Additional informations:

Code:

LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 6.6 (Santiago)
Release:        6.6
Codename:      Santiago

Code:

GNU grep 2.6.3

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images