grep lines that contain 1 character followed by another character

This will find a “b” that is not followed by “e”:

$ echo "one be
two
bring
brought" | egrep 'b[^e]'

Or if perl is available but egrep is not:

$ echo "one be
two
bring
brought" | perl -ne 'print if /b[^e]/;'

And if you want to find lines with “b” not followed by “e” but no words that contain “be” (using the \w perl metacharacter to catch another character after the b), and avoiding any words that end with b:

$ echo "lab
bribe
two
bring
brought" | perl -ne 'print if /b\w/ && ! /be/'

So the final call would:

$ perl -ne 'print if /b\w/ && ! /be/' f3.txt

Leave a Comment