From: Edgardo Portal on
On 2009-12-09, Ben Bacarisse <ben.usenet(a)bsb.me.uk> wrote:
> Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:
>
>> On Tue, 08 Dec 2009 20:14:42 +0000, pk <pk(a)pk.invalid> wrote:
>>
>>>\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|
>>>[01]?[0-9][0-9]?)\b
>>>
>>>on a single line. GNU egrep should support \b, but I'm not sure.
>>
>> I've tried the above code, but I'll get nothing to output. See the
>> following minimal example:
>>
>> $ cat -vte ips
>> 192.168.142.138$
>> 5.4$
>> 66.33.154.1$
>> 127.0.0.1$
>> 1.888.555.1212
>> $ egrep
>> '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0
>> -9]|[01]?[0-9][0-9]?)\b' ips
>
> On my system the problem is the (?:) syntax. This is from Perl REs
> and denotes a non-capturing group. I find that
>
> egrep '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' ips
>
> works fine.

Note that it does match things like 001.002.003.004,
012.034.056.099, etc. -- are those "valid" IPs?
From: Ben Bacarisse on
Edgardo Portal <egportal2002(a)yahoo.com> writes:

> On 2009-12-09, Ben Bacarisse <ben.usenet(a)bsb.me.uk> wrote:
>> Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:
>>
>>> On Tue, 08 Dec 2009 20:14:42 +0000, pk <pk(a)pk.invalid> wrote:
>>>
>>>>\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|
>>>>[01]?[0-9][0-9]?)\b
>>>>
>>>>on a single line. GNU egrep should support \b, but I'm not sure.
>>>
>>> I've tried the above code, but I'll get nothing to output. See the
>>> following minimal example:
>>>
>>> $ cat -vte ips
>>> 192.168.142.138$
>>> 5.4$
>>> 66.33.154.1$
>>> 127.0.0.1$
>>> 1.888.555.1212
>>> $ egrep
>>> '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0
>>> -9]|[01]?[0-9][0-9]?)\b' ips
>>
>> On my system the problem is the (?:) syntax. This is from Perl REs
>> and denotes a non-capturing group. I find that
>>
>> egrep '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' ips
>>
>> works fine.
>
> Note that it does match things like 001.002.003.004,
> 012.034.056.099, etc. -- are those "valid" IPs?

As far as I can tell, yes. Various RFCs on Assigned Number use
addresses with leading zeros.

--
Ben.
From: pk on
Ben Bacarisse wrote:

> Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:
>
>> On Tue, 08 Dec 2009 20:14:42 +0000, pk <pk(a)pk.invalid> wrote:
>>
>>>\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]
[0-9]|
>>>[01]?[0-9][0-9]?)\b
>>>
>>>on a single line. GNU egrep should support \b, but I'm not sure.
>>
>> I've tried the above code, but I'll get nothing to output. See the
>> following minimal example:
>>
>> $ cat -vte ips
>> 192.168.142.138$
>> 5.4$
>> 66.33.154.1$
>> 127.0.0.1$
>> 1.888.555.1212
>> $ egrep
>> '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0
>> -9]|[01]?[0-9][0-9]?)\b' ips
>
> On my system the problem is the (?:) syntax. This is from Perl REs
> and denotes a non-capturing group. I find that
>
> egrep
> '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|
[01]?[0-9][0-9]?)\b'
> ips

Well spotted. That is definitely the problem. I just copied/pasted that
regex from the web without paying too much attention.
From: Hongyi Zhao on
On Wed, 09 Dec 2009 15:40:25 +0000, Ben Bacarisse
<ben.usenet(a)bsb.me.uk> wrote:

>On my system the problem is the (?:) syntax. This is from Perl REs
>and denotes a non-capturing group. I find that

So, the following one will do the trick:

$ grep -P
'\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]
[0-9]|[01]?[0-9][0-9]?)\b' ips

Best regards.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Ben Bacarisse on
Hongyi Zhao <hongyi.zhao(a)gmail.com> writes:

> On Wed, 09 Dec 2009 15:40:25 +0000, Ben Bacarisse
> <ben.usenet(a)bsb.me.uk> wrote:
>
>>On my system the problem is the (?:) syntax. This is from Perl REs
>>and denotes a non-capturing group. I find that
>
> So, the following one will do the trick:
>
> $ grep -P
> '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4]
> [0-9]|[01]?[0-9][0-9]?)\b' ips

If you have -P. My egrep does not. I can't see the value in using a
non-portable construct like (?:). You might also want to replace \b
since not all greps have it.

--
Ben.