Regex lookahead for 'not followed by' in grep
The answer to part of your problem is here, and ack would behave the same way: Ack & negative lookahead giving errors
You are using double-quotes for grep, which permits bash to "interpret !
as history expand command."
You need to wrap your pattern in SINGLE-QUOTES:
grep 'Ui\.(?!L)' *
However, see @JonathanLeffler's answer to address the issues with negative lookaheads in standard grep
!
You probably cant perform standard negative lookaheads using grep, but usually you should be able to get equivalent behaviour using the "inverse" switch '-v'. Using that you can construct a regex for the complement of what you want to match and then pipe it through 2 greps.
For the regex in question you might do something like
grep 'Ui\.' * | grep -v 'Ui\.L'
Negative lookahead, which is what you're after, requires a more powerful tool than the standard grep
. You need a PCRE-enabled grep.
If you have GNU grep
, the current version supports options -P
or --perl-regexp
and you can then use the regex you wanted.
If you don't have (a sufficiently recent version of) GNU grep
, then consider getting ack
.