Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-26 Thread Kai Peter

On 2019-01-25 18:31, Michael Orlitzky wrote:

On 1/25/19 11:32 AM, Kai Peter wrote:


Really interesting _how_ people think. Find the error:



You're not even trying:

  $ echo 0.0.0.0 | sed 's/\.0/\./g' | sed 's/^0//g' | \
sed 's/\.0/\./g' | sed 's/\.\./.0./g' | sed 's/^0//g'
  .0..


True, but that wasn't requested.


It's trivial to enumerate all "valid" (that is, without leading zeros)
IP addresses. The most basic test that any regex should pass is that it
should do nothing on those examples.

+1

--
Sent with eQmail-1.11 beta - a fork of djb's famous qmail



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-25 Thread Michael Orlitzky
On 1/25/19 11:32 AM, Kai Peter wrote:
> 
> Really interesting _how_ people think. Find the error:
> 

You're not even trying:

  $ echo 0.0.0.0 | sed 's/\.0/\./g' | sed 's/^0//g' | \
sed 's/\.0/\./g' | sed 's/\.\./.0./g' | sed 's/^0//g'
  .0..

It's trivial to enumerate all "valid" (that is, without leading zeros)
IP addresses. The most basic test that any regex should pass is that it
should do nothing on those examples.



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-25 Thread Kai Peter

On 2019-01-24 17:40, Michael Orlitzky wrote:

On 1/24/19 4:00 AM, Gerrit Kühn wrote:


---
[me@you ~]# ip=01.02.00.0004; for d in $(echo "${ip}"|tr '.' '\n');
do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
1.2.0.4


That turns "010" into "8". Using a real programming language with a
parser is only heavyweight compared to solutions that don't work.

  $ ip=01.02.00.010; for d in $(echo "${ip}"|tr '.' '\n'); \
do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
  1.2.0.8

Really interesting _how_ people think. Find the error:

echo 01.02.00.010 | sed 's/\.0/\./g' | sed 's/^0//g' | sed 's/\.0/\./g' 
| sed 's/\.\./.0./g' | sed 's/^0//g'




--
Sent with eQmail-1.11 beta - a fork of djb's famous qmail



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-24 Thread Michael Orlitzky

On 1/24/19 4:00 AM, Gerrit Kühn wrote:


---
[me@you ~]# ip=01.02.00.0004; for d in $(echo "${ip}"|tr '.' '\n');
do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
1.2.0.4


That turns "010" into "8". Using a real programming language with a 
parser is only heavyweight compared to solutions that don't work.


  $ ip=01.02.00.010; for d in $(echo "${ip}"|tr '.' '\n'); \
do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
  1.2.0.8




Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-24 Thread Gerrit Kühn
On Wed, 23 Jan 2019 16:45:59 -0500 Michael Orlitzky  wrote
about Re: [gentoo-user] Re: OT scripting - strip zero if between period
and digit:

> > This is not a good application for a regex.

> Since that doesn't seem to be stopping anyone, here's my entry.

Since the only alternative to a regexp presented so far was using python
(which has been considered a bit heavy-weight), I'll suggest some hacky
shell code instead (here as a one-liner, would probably be nicer to do this
as a function):

---
[me@you ~]# ip=01.02.00.0004; for d in $(echo "${ip}"|tr '.' '\n');
do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
1.2.0.4
---


HTH
Gerrit



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Michael Orlitzky

On 1/23/19 2:24 PM, Grant Edwards wrote:


This is not a good application for a regex.



Since that doesn't seem to be stopping anyone, here's my entry.

sed 
's/\(0*\(255\|254\|253\|252\|251\|250\|249\|248\|247\|246\|245\|244\|243\|242\|241\|240\|239\|238\|237\|236\|235\|234\|233\|232\|231\|230\|229\|228\|227\|226\|225\|224\|223\|222\|221\|220\|219\|218\|217\|216\|215\|214\|213\|212\|211\|210\|209\|208\|207\|206\|205\|204\|203\|202\|201\|200\|199\|198\|197\|196\|195\|194\|193\|192\|191\|190\|189\|188\|187\|186\|185\|184\|183\|182\|181\|180\|179\|178\|177\|176\|175\|174\|173\|172\|171\|170\|169\|168\|167\|166\|165\|164\|163\|162\|161\|160\|159\|158\|157\|156\|155\|154\|153\|152\|151\|150\|149\|148\|147\|146\|145\|144\|143\|142\|141\|140\|139\|138\|137\|136\|135\|134\|133\|132\|131\|130\|129\|128\|127\|126\|125\|124\|123\|122\|121\|120\|119\|118\|117\|116\|115\|114\|113\|112\|111\|110\|109\|108\|107\|106\|105\|104\|103\|102\|101\|100\|99\|98\|97\|96\|95\|94\|93\|92\|91\|90\|89\|88\|87\|86\|85\|84\|83\|82\|81\|80\|79\|78\|77\|76\|75\|74\|73\|72\|71\|70\|69\|68\|67\|66\|65\|64\|63\|62\|61\|60\|59\|58\|57\|56\|55\|54\|53\|52\|51\|50\|49\|48\|47\|46\|45\|44\|43\|42\|41\|40\|39\|38\|37\|36\|35\|34\|33\|32\|31\|30\|29\|28\|27\|26\|25\|24\|23\|22\|21\|20\|19\|18\|17\|16\|15\|14\|13\|12\|11\|10\|9\|8\|7\|6\|5\|4\|3\|2\|1\|0\)\.0*\(255\|254\|253\|252\|251\|250\|249\|248\|247\|246\|245\|244\|243\|242\|241\|240\|239\|238\|237\|236\|235\|234\|233\|232\|231\|230\|229\|228\|227\|226\|225\|224\|223\|222\|221\|220\|219\|218\|217\|216\|215\|214\|213\|212\|211\|210\|209\|208\|207\|206\|205\|204\|203\|202\|201\|200\|199\|198\|197\|196\|195\|194\|193\|192\|191\|190\|189\|188\|187\|186\|185\|184\|183\|182\|181\|180\|179\|178\|177\|176\|175\|174\|173\|172\|171\|170\|169\|168\|167\|166\|165\|164\|163\|162\|161\|160\|159\|158\|157\|156\|155\|154\|153\|152\|151\|150\|149\|148\|147\|146\|145\|144\|143\|142\|141\|140\|139\|138\|137\|136\|135\|134\|133\|132\|131\|130\|129\|128\|127\|126\|125\|124\|123\|122\|121\|120\|119\|118\|117\|116\|115\|114\|113\|112\|111\|110\|109\|108\|107\|106\|105\|104\|103\|102\|101\|100\|99\|98\|97\|96\|95\|94\|93\|92\|91\|90\|89\|88\|87\|86\|85\|84\|83\|82\|81\|80\|79\|78\|77\|76\|75\|74\|73\|72\|71\|70\|69\|68\|67\|66\|65\|64\|63\|62\|61\|60\|59\|58\|57\|56\|55\|54\|53\|52\|51\|50\|49\|48\|47\|46\|45\|44\|43\|42\|41\|40\|39\|38\|37\|36\|35\|34\|33\|32\|31\|30\|29\|28\|27\|26\|25\|24\|23\|22\|21\|20\|19\|18\|17\|16\|15\|14\|13\|12\|11\|10\|9\|8\|7\|6\|5\|4\|3\|2\|1\|0\)\.0*\(255\|254\|253\|252\|251\|250\|249\|248\|247\|246\|245\|244\|243\|242\|241\|240\|239\|238\|237\|236\|235\|234\|233\|232\|231\|230\|229\|228\|227\|226\|225\|224\|223\|222\|221\|220\|219\|218\|217\|216\|215\|214\|213\|212\|211\|210\|209\|208\|207\|206\|205\|204\|203\|202\|201\|200\|199\|198\|197\|196\|195\|194\|193\|192\|191\|190\|189\|188\|187\|186\|185\|184\|183\|182\|181\|180\|179\|178\|177\|176\|175\|174\|173\|172\|171\|170\|169\|168\|167\|166\|165\|164\|163\|162\|161\|160\|159\|158\|157\|156\|155\|154\|153\|152\|151\|150\|149\|148\|147\|146\|145\|144\|143\|142\|141\|140\|139\|138\|137\|136\|135\|134\|133\|132\|131\|130\|129\|128\|127\|126\|125\|124\|123\|122\|121\|120\|119\|118\|117\|116\|115\|114\|113\|112\|111\|110\|109\|108\|107\|106\|105\|104\|103\|102\|101\|100\|99\|98\|97\|96\|95\|94\|93\|92\|91\|90\|89\|88\|87\|86\|85\|84\|83\|82\|81\|80\|79\|78\|77\|76\|75\|74\|73\|72\|71\|70\|69\|68\|67\|66\|65\|64\|63\|62\|61\|60\|59\|58\|57\|56\|55\|54\|53\|52\|51\|50\|49\|48\|47\|46\|45\|44\|43\|42\|41\|40\|39\|38\|37\|36\|35\|34\|33\|32\|31\|30\|29\|28\|27\|26\|25\|24\|23\|22\|21\|20\|19\|18\|17\|16\|15\|14\|13\|12\|11\|10\|9\|8\|7\|6\|5\|4\|3\|2\|1\|0\)\.0*\(255\|254\|253\|252\|251\|250\|249\|248\|247\|246\|245\|244\|243\|242\|241\|240\|239\|238\|237\|236\|235\|234\|233\|232\|231\|230\|229\|228\|227\|226\|225\|224\|223\|222\|221\|220\|219\|218\|217\|216\|215\|214\|213\|212\|211\|210\|209\|208\|207\|206\|205\|204\|203\|202\|201\|200\|199\|198\|197\|196\|195\|194\|193\|192\|191\|190\|189\|188\|187\|186\|185\|184\|183\|182\|181\|180\|179\|178\|177\|176\|175\|174\|173\|172\|171\|170\|169\|168\|167\|166\|165\|164\|163\|162\|161\|160\|159\|158\|157\|156\|155\|154\|153\|152\|151\|150\|149\|148\|147\|146\|145\|144\|143\|142\|141\|140\|139\|138\|137\|136\|135\|134\|133\|132\|131\|130\|129\|128\|127\|126\|125\|124\|123\|122\|121\|120\|119\|118\|117\|116\|115\|114\|113\|112\|111\|110\|109\|108\|107\|106\|105\|104\|103\|102\|101\|100\|99\|98\|97\|96\|95\|94\|93\|92\|91\|90\|89\|88\|87\|86\|85\|84\|83\|82\|81\|80\|79\|78\|77\|76\|75\|74\|73\|72\|71\|70\|69\|68\|67\|66\|65\|64\|63\|62\|61\|60\|59\|58\|57\|56\|55\|54\|53\|52\|51\|50\|49\|48\|47\|46\|45\|44\|43\|42\|41\|40\|39\|38\|37\|36\|35\|34\|33\|32\|31\|30\|29\|28\|27\|26\|25\|24\|23\|22\|21\|20\|19\|18\|17\|16\|15\|14\|13\|12\|11\|10\|9\|8\|7\|6\|5\|4\|3\|2\|1\|0\)\)/\2.\3.\4.\5/g'


[gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Grant Edwards
On 2019-01-23, Alexander Kapshuk  wrote:
> On Wed, Jan 23, 2019 at 9:41 PM Grant Edwards  
> wrote:
>> On 2019-01-23, Alexander Kapshuk  wrote:
>>
>> > This any better? :-)
>> >
>> > echo '198.088.0.01
>> > 198.088.062.01
>> > 198.088.0.001' | sed -r 's/\.0+([^.0]+)/.\1/g'
>>
>> I guess it's 'better', but it's still broken:
>>
>> $ echo '003.4.5.6' | sed -r 's/\.0+([^.0]+)/.\1/g'
>> 003.4.5.6
>>
>> This is not a good application for a regex.
>
> The OP stated that there were no leading zeros in the first octet of
> the IP address, so that case did not need to be handled.

If I had a dollar for every bug/failure that happened because somebody
relied on an input restriction like that...

-- 
Grant Edwards   grant.b.edwardsYow! You mean you don't
  at   want to watch WRESTLING
  gmail.comfrom ATLANTA?




Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Michael Orlitzky

On 1/23/19 3:08 PM, Alexander Kapshuk wrote:


The OP stated that there were no leading zeros in the first octet of
the IP address, so that case did not need to be handled.



$ echo "1.00.3.4" | sed -r 's/\.0+([^.0]+)/.\1/g'
1.00.3.4



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Alexander Kapshuk
On Wed, Jan 23, 2019 at 9:41 PM Grant Edwards  wrote:
>
> On 2019-01-23, Alexander Kapshuk  wrote:
>
> > This any better? :-)
> >
> > echo '198.088.0.01
> > 198.088.062.01
> > 198.088.0.001' | sed -r 's/\.0+([^.0]+)/.\1/g'
>
> I guess it's 'better', but it's still broken:
>
> $ echo '003.4.5.6' | sed -r 's/\.0+([^.0]+)/.\1/g'
> 003.4.5.6
>
> This is not a good application for a regex.
>
> --
> Grant Edwards   grant.b.edwardsYow! I have accepted
>   at   Provolone into my life!
>   gmail.com
>
>
The OP stated that there were no leading zeros in the first octet of
the IP address, so that case did not need to be handled.



[gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Grant Edwards
On 2019-01-23, Alexander Kapshuk  wrote:

> This any better? :-)
>
> echo '198.088.0.01
> 198.088.062.01
> 198.088.0.001' | sed -r 's/\.0+([^.0]+)/.\1/g'

I guess it's 'better', but it's still broken:

$ echo '003.4.5.6' | sed -r 's/\.0+([^.0]+)/.\1/g'
003.4.5.6

This is not a good application for a regex.

-- 
Grant Edwards   grant.b.edwardsYow! I have accepted
  at   Provolone into my life!
  gmail.com




Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Alexander Kapshuk
On Wed, Jan 23, 2019 at 4:10 PM Grant Edwards  wrote:
>
> On 2019-01-23, Alexander Kapshuk  wrote:
> >
> > How about this one?
> >
> > echo '198.088.0.01
> > 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> > 198.88.0.1
> > 198.88.62.1
>
> Also no.
>
> $ echo 198.088.0.001 |   sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> 198.88.0.01
>
>
> --
> Grant Edwards   grant.b.edwardsYow! Hello.  Just walk
>   at   along and try NOT to think
>   gmail.comabout your INTESTINES being
>almost FORTY YARDS LONG!!
>
>

This any better? :-)

echo '198.088.0.01
198.088.062.01
198.088.0.001' | sed -r 's/\.0+([^.0]+)/.\1/g'
198.88.0.1
198.88.62.1
198.88.0.1



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Kai Peter

On 2019-01-23 18:26, Neil Bothwick wrote:

On Wed, 23 Jan 2019 14:09:45 - (UTC), Grant Edwards wrote:


> How about this one?
>
> echo '198.088.0.01
> 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> 198.88.0.1
> 198.88.62.1

Also no.

$ echo 198.088.0.001 |   sed 's/\.0\([0-9][0-9]*\)/.\1/g'
198.88.0.01


This is like playing Whack-a-Mole with sed ;-)


That's the fun ;-)

I think the truth is in the middle between a twelve-pages-script and a 
one-liner. Split it, 'sed' it, check result, correct result if required, 
combine it.


--
Sent with eQmail-1.11 beta - a fork of djb's famous qmail



Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Neil Bothwick
On Wed, 23 Jan 2019 14:09:45 - (UTC), Grant Edwards wrote:

> > How about this one?
> >
> > echo '198.088.0.01
> > 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> > 198.88.0.1
> > 198.88.62.1  
> 
> Also no.
> 
> $ echo 198.088.0.001 |   sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> 198.88.0.01

This is like playing Whack-a-Mole with sed ;-)


-- 
Neil Bothwick

I know corn oil comes from corn, where does baby oil come from?


pgpVmxUInKN3A.pgp
Description: OpenPGP digital signature


[gentoo-user] Re: OT scripting - strip zero if between period and digit

2019-01-23 Thread Grant Edwards
On 2019-01-23, Alexander Kapshuk  wrote:
>
> How about this one?
>
> echo '198.088.0.01
> 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g'
> 198.88.0.1
> 198.88.62.1

Also no.

$ echo 198.088.0.001 |   sed 's/\.0\([0-9][0-9]*\)/.\1/g'
198.88.0.01


-- 
Grant Edwards   grant.b.edwardsYow! Hello.  Just walk
  at   along and try NOT to think
  gmail.comabout your INTESTINES being
   almost FORTY YARDS LONG!!