Bug 242308 - (GNU) grep -b, --byte-offset returns 0
Summary: (GNU) grep -b, --byte-offset returns 0
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
Depends on:
Reported: 2019-11-30 00:07 UTC by Marvin Jones
Modified: 2020-12-08 14:06 UTC (History)
5 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
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

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
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

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.
Comment 4 commit-hook freebsd_committer 2020-12-08 14:06:06 UTC
A commit references this bug:

Author: kevans
Date: Tue Dec  8 14:05:27 UTC 2020
New revision: 368439
URL: https://svnweb.freebsd.org/changeset/base/368439

  src.opts.mk: switch to bsdgrep as /usr/bin/grep

  This has been years in the making, and we all knew it was bound to happen
  some day. Switch to the BSDL grep implementation now that it's been a
  little more thoroughly tested and theoretically supports all of the
  extensions that gnugrep in base had with our libregex(3).

  Folks shouldn't really notice much from this update; bsdgrep is slower than
  gnugrep, but this is currently the price to pay for fewer bugs. Those
  dissatisfied with the speed of grep and in need of a faster implementation
  should check out what textproc/ripgrep and textproc/the_silver_searcher
  can do for them.

  I have some WIP to make bsdgrep faster, but do not consider it a blocker
  when compared to the pros of switching now (aforementioned bugs, licensing).

  PR:		228798 (exp-run)
  PR:		128645, 156704, 166842, 166862, 180937, 193835, 201650
  PR:		232565, 242308, 246000, 251081, 191086, 194397
  Relnotes:	yes, please