You can go for the following two solutions:
grep -ie 'b[^e]' input_file.txt
or
grep -ie 'b.' input_file.txt | grep -vi 'be'
The first one does use regex:
'b[^e]'
meansb followed by any symbol that is not e
-i
is to ignore case, with this option lines containingB
orb
that are not directly followed bye
orE
will be accepted
The second solution calls grep twice:
- the first time you look for patterns that contains b only to select those lines
- the resulting lines are filtered by the second grep using
-v
to reject lines containingbe
- both grep are ignoring the case by using
-i
-
if
b
must absolutely be followed by another character then useb.
(regex meaningb
followed by any other char) otherwise if you want to also accept lines whereb
is not followed by any other character at all you can just useb
in the first grep call instead ofb.
.grep -ie 'b' input_file.txt | grep -vi 'be'
input:
BEBE
bebe
toto
abc
bobo
result:
abc
bobo
2
solved grep lines that contain 1 character followed by another character