Is there a simple solution to also extract one word before and one word after along with the matched word? For example, assuming the following text
... put returns between paragraphs ...
... the function returns void ...
the search for returns
should return
put returns between
function returns void
I am not a bash expert, but could put together the following
grep -o -P "(?:[a-zA-Z'-]+[^a-zA-Z'-]+){1}returns(?:[^a-zA-Z'-]+[a-zA-Z'-]+){1}" TEXT.FILE
but not sure if this catches all.