Gentoo Archives: gentoo-user

From: Adam Carter <adamcarter3@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT scripting - strip zero if between period and digit
Date: Wed, 23 Jan 2019 03:27:17
Message-Id: CAC=wYCFAN9Ko56Hh1XdiT6jPeghCKKhyctG0Yr97jtm-guk-LA@mail.gmail.com
In Reply to: Re: [gentoo-user] OT scripting - strip zero if between period and digit by Michael Orlitzky
1 On Wed, Jan 23, 2019 at 12:34 AM Michael Orlitzky <mjo@g.o> wrote:
2
3 > On 1/21/19 9:55 PM, David Haller wrote:
4 > >
5 > > $ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \
6 > > sed 's/0*\([[:digit:]]\+\)/\1/g'
7 > > 0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3
8 > >
9 >
10 > There are actually more than four examples that it needs to work on. And
11 > more to the point, this is going to destroy any other numbers it finds
12 > in the input. Phone numbers, zip codes, addresses, credit cards numbers,
13 > timestamps, etc. will all get clobbered. It takes like 10 lines of
14 > python to do this right; it's silly to invest a ton of effort trying to
15 > come up with a regex solution that accidentally works.
16 >
17 >
18 Thanks Michael. The input data is constrained in ways I didnt list, so it
19 might be possible to get away with a regex, but I appreciate you
20 highlighting the risk of what sounds like a brittle approach.
21
22 I am hopeful that one day learning python will make it to the top of my
23 priority list.