Repository navigation
grep: print the group separator with -o and context options - #188
sarankumar1325 wants to merge 1 commit into
Conversation
GNU grep does not print context lines under -o, but it still tracks the context groups and prints the group separator between groups that are not adjacent. Keep the context settings with -o and skip only the context lines themselves when writing. Fixes uutils#175
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Fixes #175
With
-o, GNU grep doesn't print context lines, but it still tracks the context groups and prints the--separator (or--group-separator) between groups that aren't adjacent. uutils grep zeroed the context and clearedhas_contextwhenever-owas given, so the separator never appeared:The context options are now kept with
-o, andWriter::write_lineskips non-matching (context) lines when-ois set, so the group tracking insession_write_match_with_contextworks as it does without-o. Output with-ostill never includes context lines, which was the point of #67/#72.Checked against GNU grep 3.11 on my machine:
-A1,-B1,-C1 -n(adjacent groups, no separator),-A0,--group-separator=XX,--no-group-separator,-b,-m1,-c,-l,-v -o -A0,--color=alwaysand-T -nall match. The one remaining difference, the separator between files with-A0 f1 f2, also happens without-oand is what #131 is about.Tests:
only_matching_with_context_keeps_group_separator; it fails on main. The existingonly_matching_with_contextstill passes.cargo test,cargo fmt --all -- --checkandcargo clippy --all-targets --workspace -- -D warningspass locally.I used an AI assistant (Grok Bot) to help write this change. I reviewed the diff, compared the output with GNU grep 3.11 and ran the tests above.