Find the answer to your Linux question:
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... ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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...

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    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):
    Code:
    /A(?!B)/
    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
  •