Skip to content

grep: print context matches with -v -o - #235

Open
yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-invert-only-matching-context
Open

yunusarda-sudo wants to merge 2 commits into
uutils:mainfrom
yunusarda-sudo:grep-invert-only-matching-context

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

With -v, the selected lines have no match for -o to print. GNU grep still prints the matches found on the surrounding context lines (2-dog rather than an empty result).

only_matching still suppresses context when -v is not used.

Closes #209.

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (b2fd25a) to head (e2423d1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #235      +/-   ##
==========================================
- Coverage   97.19%   97.17%   -0.02%     
==========================================
  Files           6        6              
  Lines        2248     2268      +20     
  Branches      243      246       +3     
==========================================
+ Hits         2185     2204      +19     
- Misses         63       64       +1     
Flag Coverage Δ
macOS_latest 98.08% <100.00%> (-0.03%) ⬇️
ubuntu_latest 98.08% <100.00%> (-0.03%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

Warning

uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-invert-only-matching-context (e2423d1) with main (b2fd25a)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

With -v, selected lines have no match to show under -o, so GNU grep
prints the matches found on the surrounding context lines instead.
Closes uutils#209.
@yunusarda-sudo
yunusarda-sudo force-pushed the grep-invert-only-matching-context branch from 7925d68 to e2423d1 Compare November 25, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep - -v -o with -A/-B/-C prints nothing; GNU prints the matches found in the context lines

1 participant