Bug 242308

Summary: (GNU) grep -b, --byte-offset returns 0
Product: Base System Reporter: Marvin Jones <marvin>
Component: binAssignee: Kyle Evans <kevans>
Status: New ---    
Severity: Affects Only Me CC: bugs, emaste, ish, kevans, pi
Priority: ---    
Version: 12.1-RELEASE   
Hardware: Any   
OS: Any   

Description Marvin Jones 2019-11-30 00:07:37 UTC
(My brand new login - first time reporting a bug - apologies if...)

grep'ping for a byte offset always returns 0 for the result.
Searching "FreeBSD Bugzilla – Bug List" shows no other reports.

Ubuntu 16.04:

jonesy@nix5:~$ a='now is the time for all good men to come to the aid of the party'
jonesy@nix5:~$ echo $a | grep -b -o  good
24:good


FreeBSD 12.1 

[jonz~]a='now is the time for all good men to come to the aid of the party'
[jonz~]echo $a | grep -b -o  good
0:good
Comment 1 Masachika ISHIZUKA 2019-11-30 00:39:29 UTC
(In reply to Marvin Jones from comment #0)

/usr/bin/grep in 13-current has the same bug.
gnugrep in ports/textproc works fine.
Comment 2 Ed Maste freebsd_committer 2019-12-02 18:11:22 UTC
Thank you for the report.

I build WITH_BSD_GREP and it doesn't have this problem:

% grep --version
grep (BSD grep) 2.6.0-FreeBSD
% a='now is the time for all good men to come to the aid of the party'
% echo $a | grep -b -o good
24:good

The most likely fix for this in FreeBSD is to wrap up the rest of the work to make BSD_GREP the default.
Comment 3 Kyle Evans freebsd_committer 2020-01-31 18:14:23 UTC
Take, as this will go away with our future gnugrep retirement party.

I do recommend using bsdgrep if you specifically need a grep in base (and don't particularly need GNU extensions), or installing textproc/gnugrep for a less buggy version of a grep with GNU extensions.