Forum: Cfengine Help
Subject: Re: regex help
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,21705,21713#msg-21713
The negative lookbehind is zero-width, so you need the rest of the pattern
around it to match a complete line if the zero-width piece was removed. That's
the hardest part for people to remember, it seems - you basically have to match
the zero-width part twice. Therefore, you proably want something like this
(truncated with a .* for my convenience)
(:?\S+\s+){5}(?<!00 3 1 \* \*\s)\s*/usr/scripts.*
So you have a pattern which says the line starts with five space-separated
non-space fields, and that's followed by "your path which was not preceeded by
your desired pattern." You might need a \s* at the beginning as well,
depending on whether or not a line starting with space is ok. I forget.
I used \s)\s* at the end of the lookbehind pattern because you can't have a
variable-width lookbehind in perl, but it should probably work regardless of
the amount of whitespace. Here's proof that the idea works. ;)
user@host
$ cat /tmp/file
1 2 3 4 5 hello world
1 2 4 4 5 hello world
user@host
$ perl -nle'print if /^(:?\S+\s+){5}(?<!1 2 3 4 5\s)\s*hello/' /tmp/file
1 2 4 4 5 hello world
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine