Subject: grep recently shows the filename with -o , but it shouldn't.

From: "Joerg M. Sigle" <[email-masked]>
Date: Tue, 10 Oct 2023 12:58:08 +0200

Hello GNU grep team

I have grep (GNU grep) 3.6 on a Debian / Devuan Linux system.

Recently I noticed that when using the -o switch, grep also shows the filename for each hit in front of the desired output, and a ":" as separator.
IIRC this was not the case in previous versions of grep [but please correct me if I'm wrong here].

In any case, the filename: is NOT shown before matching content when the -o switch is not used.

According to the manual, the -o switch should only limit output to matching parts, and NOT ADDITIONALLY activate the output of filename:

-o, --only-matching
	Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

N.B.:
Showing the filename ONLY instead of matching lines/only matching part) IS already controlled with the -l switch.
So a different switch would be needed to show the filename IN ADDITION to the output of -o.
I think, somebody thought they'd do something beneficial by showing the filename in front of the output of -o, but I'm afraid they are not.
And I'm also afraid that this needs some workaround to remove the filename again for many applications of grep,
so changing back to the expected behaviour might cause trouble again, of course.

Example:

$ grep  -o PV1.... *.hl7

Currently produced output (supposedly wrong):

PAT_20231010_112021_010166.hl7:PV1|1|O
PAT_20231010_112021_010167.hl7:PV1|1|O
PAT_20231010_112420_010168.hl7:PV1|1|I
PAT_20231010_112421_010169.hl7:PV1|1|I
PAT_20231010_112421_010170.hl7:PV1|1|I
...

Desired output (supposedly right):
PV1|1|O
PV1|1|O
PV1|1|I
PV1|1|I
PV1|1|I
...

Thanks and kind regards, Joerg Sigle

-- 
-------------------------------------------------------------------
Dr. med. Jörg M. Sigle                             +41 76 276 86 94
http://www.ql-recorder.com                         +41 32 510 23 46
http://www.jsigle.com                           +49 176 96 43 54 13