>
> For accuracy, under POSIX, `grep` indeed is required to always print whole
lines, however GNU `grep` has...
-o, --only-matching
Print only the matched (non-empty) parts of a matching
line, with each such part on a separate output line.
...and BSD `grep` has...
-o, --only-matching
Prints only the matching part of the lines.
GNU and BSD `grep` are common on newer distros; the POSIX (not to use '-o')
specification is useful for portability and older installations.
~ $ echo foo | grep -o o
o
o
~ $ grep --version
grep (GNU grep) 3.12
Wiley
On Tue, 20 May 2025 16:20:46 -0400, Greg Wooledge wrote:
> > grep always prints whole lines. It doesn't just print the matching part
> > of a line.