Positive/Negative lookahead with grep and perl
问题 my login.txt file contains following entries abc def abc 123 def abc abc de tha ewe when i do the positive lookahead using perl, i'm getting the following result cat login.txt | perl -ne 'print if /(?)abc\s(?=def)/' abc def when i use grep i'm getting the following result cat login.txt | grep -P '(?<=abc)\s(?=def)' abc def negative lookahed results as follows from perl and grep. cat login | perl -ne 'print if /(?)abc\s(?!def)/' abc 123 def abc abc de grep result cat login.txt | grep -P '(?<