GNU bug report logs - #51560
Pattern matching not working as expected

Previous Next

Package: sed;

Reported by: Rob Dyck <rob.dyck <at> telus.net>

Date: Mon, 1 Nov 2021 22:45:02 UTC

Severity: normal

To reply to this bug, email your comments to 51560 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#51560; Package sed. (Mon, 01 Nov 2021 22:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rob Dyck <rob.dyck <at> telus.net>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Mon, 01 Nov 2021 22:45:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rob Dyck <rob.dyck <at> telus.net>
To: bug-sed <at> gnu.org
Subject: Pattern matching not working as expected
Date: Mon, 01 Nov 2021 14:17:19 -0700
[Message part 1 (text/plain, inline)]
Context:
sed (GNU sed) 4.8 
Copyright (C) 2020 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. 

Written by Jay Fenlason, Tom Lord, Ken Pizzini, 
Paolo Bonzini, Jim Meyering, and Assaf Gordon. 

This sed program was built with SELinux support. 
SELinux is enabled on this system.

 The problem:
I am filtering the multi-line output if the ipcal command.
The full outlook looks like  --
ipcalc dead:beef::/64 
                                                                                                                                        
Full Network:   dead:beef:0000:0000:0000:0000:0000:0000/64 
Network:        dead:beef::/64 
                                                                                                                                                 
Netmask:        ffff:ffff:ffff:ffff:: = 64 
                                                                                                                                     
                                                                                                                                                                   
            
Address space:  Reserved 
HostMin:        dead:beef:: 
                                                                                                                                                    
HostMax:        dead:beef::ffff:ffff:ffff:ffff 
                                                                                                                                 
Hosts/Net:      2^(64) = 18446744073709551616

The following example is a simplified version of what I originally was trying to do.
Extract the lines that start with Network
This works as expected --~]$ ipcalc dead:beef::/64 | sed -n '/^Netwo*/p' 
Network:        dead:beef::/64
So ^Netwo* finds the only line that starts with Network.
My reasoning is that ^Netw shoud give the same result ( elimate o ).
But no
ipcalc dead:beef::/64 | sed -n '/^Netw*/p' 
Network:        dead:beef::/64 
Netmask:        ffff:ffff:ffff:ffff:: = 64

Netmask get pulled in.
I realize that sed can use various inputs to accomplish a task so I am not really interested 
here in other methods.

Why does ^Netw* match Netmask?

Am I missing something rather fundamental or is this a bug?




[Message part 2 (text/html, inline)]

Information forwarded to bug-sed <at> gnu.org:
bug#51560; Package sed. (Tue, 02 Nov 2021 10:13:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Davide Brini <dave_br <at> gmx.com>
To: bug-sed <at> gnu.org
Subject: Re: bug#51560: Pattern matching not working as expected
Date: Tue, 2 Nov 2021 11:12:18 +0100
On Mon, 01 Nov 2021 14:17:19 -0700, Rob Dyck <rob.dyck <at> telus.net> wrote:

> Extract the lines that start with Network
> This works as expected --~]$ ipcalc dead:beef::/64 | sed -n '/^Netwo*/p'
> Network:        dead:beef::/64
> So ^Netwo* finds the only line that starts with Network.

Remember that the * quantifier applies to the preceding element, so more
correctly, "^Netwo*" fins the lines starting with:

N, e, t, w, zero or more o

(you probably see where this is going already)

> My reasoning is that ^Netw shoud give the same result ( elimate o ).
> But no
> ipcalc dead:beef::/64 | sed -n '/^Netw*/p'
> Network:        dead:beef::/64
> Netmask:        ffff:ffff:ffff:ffff:: = 64
>
> Netmask get pulled in.

Because "^Netw*" finds lines staring with:

N, e, t, zero or more w

So sed is correct.

--
D.




Information forwarded to bug-sed <at> gnu.org:
bug#51560; Package sed. (Tue, 02 Nov 2021 15:00:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rob Dyck <rob.dyck <at> telus.net>
To: 51560 <at> debbugs.gnu.org, bug-sed <at> gnu.org
Cc: Davide Brini <dave_br <at> gmx.com>
Subject: Re: bug#51560: Pattern matching not working as expected
Date: Tue, 02 Nov 2021 07:39:33 -0700
Thank you. I was missing something fundamental. my previous experience with 
something similar to regular expressions was with telephone apps. For instance 
00* represented the international dialing code followed by any number of 
digits.

On Tuesday, November 2, 2021 3:12:18 A.M. PDT Davide Brini wrote:
> On Mon, 01 Nov 2021 14:17:19 -0700, Rob Dyck <rob.dyck <at> telus.net> wrote:
> > Extract the lines that start with Network
> > This works as expected --~]$ ipcalc dead:beef::/64 | sed -n '/^Netwo*/p'
> > Network:        dead:beef::/64
> > So ^Netwo* finds the only line that starts with Network.
> 
> Remember that the * quantifier applies to the preceding element, so more
> correctly, "^Netwo*" fins the lines starting with:
> 
> N, e, t, w, zero or more o
> 
> (you probably see where this is going already)
> 
> > My reasoning is that ^Netw shoud give the same result ( elimate o ).
> > But no
> > ipcalc dead:beef::/64 | sed -n '/^Netw*/p'
> > Network:        dead:beef::/64
> > Netmask:        ffff:ffff:ffff:ffff:: = 64
> > 
> > Netmask get pulled in.
> 
> Because "^Netw*" finds lines staring with:
> 
> N, e, t, zero or more w
> 
> So sed is correct.
> 
> --
> D.








Information forwarded to bug-sed <at> gnu.org:
bug#51560; Package sed. (Tue, 02 Nov 2021 15:00:02 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 56 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.