FreeBSD (including MacOS) version does have such feature.
Well -B -1
works, it shows all the lines before the match from the beginning of the file.
... | grep -B -1 -- "foo"
Same for -A -1
, it shows all the lines after the match to the end of the file.
... | grep -A -1 -- "foo"
May be useful for some, It doesn't work with GNU implementation included within Ubuntu.