You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
grep - -v -o with -A/-B/-C prints nothing; GNU prints the matches found in the context lines #209
With -v -o, the selected lines are the non-matching ones, so they have nothing to print.
When context is also requested, GNU grep prints, for each context line (a line that does
match), its matching parts with the context separator - (2-dog), plus -- between
non-adjacent groups. uu_grep drops the context entirely whenever -o is given, so it
prints nothing.
Related: #175 / PR #188 restore the -- separators for -o with context, but keep skipping
context lines, so they do not cover this case.
Exposed by the GNU test yesno (tests #24-v -C 1 -o and #38-m 3 -v -C 1 -o). The other yesno failures are #175 (tests #4, #20) and #156 (--group=XYZ, --no-gr, tests #5, #6, #8, #9, #25, #26).
Reproduction
$ printf'cat\ndog\ncat\ncat\ncat\ndog\n'> pets
Rust (incorrect)
$ ./target/release/grep -n -v -A 1 -o dog pets
# Output: (none)# Exit code: 0
GNU (correct)
$ LC_ALL=C /usr/bin/grep -n -v -A 1 -o dog pets
2-dog
6-dog
# Exit code: 0
Test
#[test]fninvert_only_matching_prints_context_matches(){let(_s,mut c) = ucmd();
c.args(&["-n","-v","-B","1","-o","ant"]).pipe_in("ant\nbee\nwasp\nbee\nant\n").succeeds().stdout_only("1-ant\n");}
Activity
grep: print context matches with -v -o