I've got the following
This is the first line. This is the middle line. This is the last line.
And I'm trying to grep the middle line just by the word
middle and return the surroundings (as example), so I can highlight the whole sentence (which is especially useful when using with context option).
It does work without the color:
$ grep -o --color=none '.\+ middle .\+' foo.txt This is the middle line.
But the same command doesn't work with color:
$ grep -o --color=auto '.\+ middle .\+' foo.txt (empty line)
-o it doesn't make any difference.
Although it works when filtering only the first half of the line:
$ grep -o --color=auto '.\+ middle' foo.txt This is the middle
but not with the second half (
Why this doesn't work as expected and how can I fix it? Is it a bug or I can't use two regex expressions at the same time for some reason?
Tested on OS X with:
$ grep --version grep (BSD grep) 2.5.1-FreeBSD
Although it seems to work on Linux, so I'm confused.