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

2019-01-23 Thread David Haller
Hello, On Wed, 23 Jan 2019, Adam Carter wrote: >> $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ >> sed 's/0*\([[:digit:]]\+\)/\1/g' >> 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 > >So [[:digit:]] is another way of writing [0-9] and the + just means another >instance of the proceeding expression,

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

2019-01-23 Thread Michael Orlitzky
On 1/23/19 5:52 AM, Wols Lists wrote: I've just done a bit of digging, and would this work to match an octet? [0-9][0-9]?[0-9]? It doesn't match 0123. Regardless, using [0-9] is destined to fail because it will match things like 999 that also aren't an octet.

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

2019-01-23 Thread Wols Lists
On 23/01/19 07:37, Alexander Kapshuk wrote: > On Wed, Jan 23, 2019 at 9:05 AM Paul Colquhoun > wrote: >> >> On Wednesday, 23 January 2019 5:52:57 PM AEDT Alexander Kapshuk wrote: >>> On Wed, Jan 23, 2019 at 5:20 AM Adam Carter wrote: >> François-Xavier > > My bad, it should be: >

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

2019-01-22 Thread Alexander Kapshuk
On Wed, Jan 23, 2019 at 9:05 AM Paul Colquhoun wrote: > > On Wednesday, 23 January 2019 5:52:57 PM AEDT Alexander Kapshuk wrote: > > On Wed, Jan 23, 2019 at 5:20 AM Adam Carter wrote: > > >> > François-Xavier > > >> > > >> My bad, it should be: > > >> > > >> sed 's/0*\([0-9][0-9]*\)/\1/g' > > >>

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

2019-01-22 Thread Paul Colquhoun
On Wednesday, 23 January 2019 5:52:57 PM AEDT Alexander Kapshuk wrote: > On Wed, Jan 23, 2019 at 5:20 AM Adam Carter wrote: > >> > François-Xavier > >> > >> My bad, it should be: > >> > >> sed 's/0*\([0-9][0-9]*\)/\1/g' > >> > >> (tests are indeed needed!) > > > > Many thanks François. This

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

2019-01-22 Thread Alexander Kapshuk
On Wed, Jan 23, 2019 at 5:20 AM Adam Carter wrote: >> >> > François-Xavier >> > >> > >> >> My bad, it should be: >> >> sed 's/0*\([0-9][0-9]*\)/\1/g' >> >> (tests are indeed needed!) > > > Many thanks François. This is almost right, but it is also stripping zeros > that follow a letter, and I

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

2019-01-22 Thread François-Xavier CARTON
Le 23/01/2019 à 04:19, Adam Carter a écrit : > François-Xavier > > My bad, it should be: sed 's/0*\([0-9][0-9]*\)/\1/g' (tests are indeed needed!) Many thanks François. This is almost right, but it is also stripping zeros that follow a letter, and I only want it

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

2019-01-22 Thread Paul Colquhoun
On Wednesday, 23 January 2019 2:32:43 PM AEDT Adam Carter wrote: > > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ > > > > sed 's/0*\([[:digit:]]\+\)/\1/g' > > > > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 > > Hi David - thanks for that. > > So [[:digit:]] is another way of writing [0-9] and

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

2019-01-22 Thread Adam Carter
> > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ > sed 's/0*\([[:digit:]]\+\)/\1/g' > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 > > > Hi David - thanks for that. So [[:digit:]] is another way of writing [0-9] and the + just means another instance of the proceeding expression, right, so your and

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

2019-01-22 Thread Adam Carter
On Wed, Jan 23, 2019 at 12:34 AM Michael Orlitzky wrote: > On 1/21/19 9:55 PM, David Haller wrote: > > > > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ > > sed 's/0*\([[:digit:]]\+\)/\1/g' > > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 > > > > There are actually more than four examples that it

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

2019-01-22 Thread Adam Carter
> > > François-Xavier > > > > > > My bad, it should be: > > sed 's/0*\([0-9][0-9]*\)/\1/g' > > (tests are indeed needed!) > Many thanks François. This is almost right, but it is also stripping zeros that follow a letter, and I only want it to strip zeros that are proceeded by a period. There are

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

2019-01-22 Thread Michael Orlitzky
On 1/21/19 9:55 PM, David Haller wrote: $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \ sed 's/0*\([[:digit:]]\+\)/\1/g' 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3 There are actually more than four examples that it needs to work on. And more to the point, this is going to destroy any other

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

2019-01-22 Thread David Haller
Hello, On Mon, 21 Jan 2019, Michael Orlitzky wrote: >On 1/21/19 6:50 PM, Adam Carter wrote: >> I need to clean up a file which has IP addresses with leading zeros in >> some of the octets so I need to make, say, .09 into .9 >> >> How do i do that in sed/awk/whatever? > >The first thing you

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

2019-01-21 Thread François-Xavier CARTON
Le 22/01/2019 à 03:05, François-Xavier CARTON a écrit : Le 22/01/2019 à 00:50, Adam Carter a écrit : I need to clean up a file which has IP addresses with leading zeros in some of the octets so I need to make, say, .09 into .9 How do i do that in sed/awk/whatever? I believe that should do:

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

2019-01-21 Thread François-Xavier CARTON
Le 22/01/2019 à 00:50, Adam Carter a écrit : I need to clean up a file which has IP addresses with leading zeros in some of the octets so I need to make, say, .09 into .9 How do i do that in sed/awk/whatever? I believe that should do: sed 's/0*\([0-9]\)/\1/g' eg. $ sed

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

2019-01-21 Thread Andrew Udvare
On 21/01/2019 18:50, Adam Carter wrote: > I need to clean up a file which has IP addresses with leading zeros in > some of the octets so I need to make, say, .09 into .9 > > How do i do that in sed/awk/whatever? A regex would be difficult. Parser is what you want. You could use Python's

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

2019-01-21 Thread Grant Taylor
On 1/21/19 5:02 PM, Michael Orlitzky wrote: You need a parser, not a regular expression. The first thing that came to mind is splitting the values and passing them through printf. (You can do it with a regex, but it's going to be one of those comical twelve-page-long things.) I don't

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

2019-01-21 Thread Michael Orlitzky
On 1/21/19 6:50 PM, Adam Carter wrote: I need to clean up a file which has IP addresses with leading zeros in some of the octets so I need to make, say, .09 into .9 How do i do that in sed/awk/whatever? The first thing you should do is construct a bunch of test cases, with all of the

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

2019-01-21 Thread Adam Carter
I need to clean up a file which has IP addresses with leading zeros in some of the octets so I need to make, say, .09 into .9 How do i do that in sed/awk/whatever?