Bug 218806 - bsdgrep(1)'s -o flag with context is completely wrong
Summary: bsdgrep(1)'s -o flag with context is completely wrong
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks: 230332 287396
  Show dependency treegraph
 
Reported: 2017-04-22 05:38 UTC by Kyle Evans
Modified: 2025-06-10 13:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle Evans freebsd_committer freebsd_triage 2017-04-22 05:38:57 UTC
Compare, with d_context_a.in from /usr/tests/usr.bin/grep:

$ gnugrep -C1 -o pig d_context_a.in               
pig
pig
--
pig
pig
pig
# Behavior is same on newer gnugrep.
$ grep -C1 -o pig d_context_a.in 
pig
Boar, sow, barrow, or gilt --
pig
Though mountains may topple and tilt.
--
Though you may be thrown over by Tabby and Rover,
pig
pig
pig
                -- Thomas Pynchon, "Gravity's Rainbow"
# Ugh

I note here that it *looks* like we should do all of the normal context behavior but not actually print the context, just the lines that actually matched and the separators that comes with context. I'll have to create some further test cases for different scenarios of overlapping/adjacency behavior of both matching lines and non-matching lines to make sure that's right.

This is likely a really strange corner case that probably won't have any practical application, but consistency is good.
Comment 1 Wolfram Schneider freebsd_committer freebsd_triage 2024-04-29 08:04:47 UTC
I can reproduce that bsdgrep is different than gnugrep in this example.

However, ripgrep behaves like bsdgrep and highlights the "pig" part of the output in red on an interactive terminal.

Should we close the issue since it works as intended?