bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26576: -v when used with -C


From: Eric Blake
Subject: bug#26576: -v when used with -C
Date: Thu, 20 Apr 2017 14:34:47 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0

On 04/20/2017 11:51 AM, Assaf Gordon wrote:

> If I may suggest the following sed program:
> 
>  $ cat file
>  a
>  b
>  c
>  bla1
>  bla2
>  UGLY
>  bla3
>  bla4
>  e
>  f
>  g
> 
>  $ sed -n ':x 1,2{N;bx} ; /UGLY/{ N;N;z;bx }; /./P;N;D' file

Works as long as lines 1 and 2 do not contain UGLY. But misbehaves if
UGLY appears early:

$ printf '2\nUGLY\n3\n4\nc\nd\n' | sed -n ':x 1,2{N;bx};
/UGLY/{N;N;z;bx}; /./P;N;D'
d

Oops - missed c.

Also misbehaves if two occurrences of UGLY appear with overlapping context:

$ printf 'a\nb\n1\n2\nUGLY\n3\nUGLY\n4\n5\nc\nd\n' | sed -n ':x
1,2{N;bx}; /UGLY/{N;N;z;bx}; /./P;N;D'
a
b
4
5
c
d

Oops - didn't filter 4 and 5.

May be fixable with even more magic, perhaps by using the hold buffer to
track the status of the last three lines, and suppressing output if any
of the last three inputs were UGLY.  But more complicated than I want to
spend time on for the sake of this email.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]