Results 1 to 2 of 2
Hi,
I have a big file (over a thousand records) e.g.:
store id: A
Processing...
store id: B
Processing...
store id: C
store id: D
Processing...
store id: E
Processing...
...
- 01-06-2011 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 12
find a pattern not followed by another pattern
Hi,
I have a big file (over a thousand records) e.g.:
store id: A
Processing...
store id: B
Processing...
store id: C
store id: D
Processing...
store id: E
Processing...
....
And for instance in the above example "store id: C" was not followed by the "Processing..." pattern, so I konw "store id: C" was not processed. Is there a one liner that I can use (preferably grep since I am most familiar with) to extract "store id: C" (or stores that are not followed by the "Processing..." pattern?
Any thoughts would be highly appreciated.
Thanks
cheers...
- 01-07-2011 #2
Not with grep. grep only supports POSIX regular expressions and extended regular expressions.
What you are looking for is called a negative lookahead assertion. It is basically a zero-length match that asserts that something does not exist. For instance (using Perl syntax):
This matches any instance of 'A' that is NOT immediately followed by 'B'. It does not match the character following 'A' (hence this is a zero-length match).Code:/A(?!B)/
Perl and Ruby both support these, as do Vim regular expressions. I'm sure that they are supported elsewhere as well.DISTRO=Arch
Registered Linux User #388732


Reply With Quote