Skip to content

grep: make '-o' override context arguments#72

Open
Froloket64 wants to merge 3 commits into
uutils:mainfrom
Froloket64:main
Open

grep: make '-o' override context arguments#72
Froloket64 wants to merge 3 commits into
uutils:mainfrom
Froloket64:main

Conversation

@Froloket64

@Froloket64 Froloket64 commented Jun 28, 2026

Copy link
Copy Markdown

Now passing -o or --only-matching ignores any context arguments, like GNU grep does.

Fixes #67 (funny).

Verification

I used this script to test correctness:

#!/usr/bin/env bash

TARGET=./target/debug/grep

printf "uutils:\n"
printf 'aa\nbb\ncc\nxx\n' | "$TARGET" -e 'aa' -o -A 2
printf 'aa\nbb\ncc\nxx\n' | "$TARGET" -e 'xx' -o -B 2
printf 'aa\nbb\ncc\nxx\n' | "$TARGET" -e 'cc' -o -C 2
printf 'aa\nbb\ncc\nxx\n' | "$TARGET" -e 'xx' -o -B 2 -n

printf "gnu:\n"
printf 'aa\nbb\ncc\nxx\n' | grep --color=always -e 'aa' -o -A 2
printf 'aa\nbb\ncc\nxx\n' | grep --color=always -e 'xx' -o -B 2
printf 'aa\nbb\ncc\nxx\n' | grep --color=always -e 'cc' -o -C 2
printf 'aa\nbb\ncc\nxx\n' | grep --color=always -e 'xx' -o -B 2 -n

@sylvestre

Copy link
Copy Markdown
Contributor

please add tests in tests/

@codspeed-hq

codspeed-hq Bot commented Jun 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing Froloket64:main (33ae27a) with main (670669e)

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.

@Froloket64

Copy link
Copy Markdown
Author

Sorry, had trouble with forked branches so had to do an extra merge.

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.

-o should suppress -A/-B/-C context, but uu_grep still prints context lines

2 participants