Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    find a pattern not followed by another pattern


    I have a big file (over a thousand records) e.g.:

    store id: A
    store id: B
    store id: C
    store id: D
    store id: E

    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.



  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    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).

    Perl and Ruby both support these, as do Vim regular expressions. I'm sure that they are supported elsewhere as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts