On Sat, Dec 25, 2021 at 04:44:11PM -0800, Greg Steuck wrote: > The separator doesn't get printed when I use this script on OpenBSD. It > does get printed on FreeBSD or if I used GNU grep. The issue appears to > be an off-by-one of some sort because removing the empty line makes the > separator disappear on both systems. > > #!/bin/sh > > grep -E -A6 '^(.w)?g' <<'EOF' > $wg > a > b > c > d > e > f > > g = \ ds -> > h > i > j > EOF >
Hi, please include the expected output and the output seen in bug reports, it makes the initial diagnosis much easier. I now had to run your testcase on another system to see what you meant. BTW, on MacOS I do see the separator with your test, both with the empty line and without it. ANyway, here's an attempt at a fix. Without much coffee, so beware. -Otto Test script I used: grep -E -A6 X << 'EOF' X 1 2 3 4 X 1 2 3 4 5 6 7 X 1 2 3 4 5 6 X 1 EOF Output with diff on and OpenBSD and MAcOS: X 1 2 3 4 X 1 2 3 4 5 6 -- X 1 2 3 4 5 6 -- X 1 Index: util.c =================================================================== RCS file: /cvs/src/usr.bin/grep/util.c,v retrieving revision 1.63 diff -u -p -r1.63 util.c --- util.c 23 Jul 2020 20:19:27 -0000 1.63 +++ util.c 26 Dec 2021 08:20:10 -0000 @@ -258,8 +258,7 @@ print: if ((tail > 0 || c) && !cflag && !qflag) { if (c) { - if (first > 0 && tail == 0 && (Bflag < linesqueued) && - (Aflag || Bflag)) + if (first > 0 && tail == 0 && (Aflag || (Bflag && Bflag < linesqueued))) printf("--\n"); first = 1; tail = Aflag;