bash-4.2$ echo 'one > Bar two Foo > three > ' | grep -A1 'Foo' | grep -B1 'Bar' | grep 'Foo' Bar two Foo