Gentoo Archives: gentoo-user

From: "Gerrit Kühn" <gerrit.kuehn@×××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit
Date: Thu, 24 Jan 2019 09:00:37
Message-Id: 20190124100026.2b62e377dc268195c4241d0f@aei.mpg.de
In Reply to: Re: [gentoo-user] Re: OT scripting - strip zero if between period and digit by Michael Orlitzky
1 On Wed, 23 Jan 2019 16:45:59 -0500 Michael Orlitzky <mjo@g.o> wrote
2 about Re: [gentoo-user] Re: OT scripting - strip zero if between period
3 and digit:
4
5 > > This is not a good application for a regex.
6
7 > Since that doesn't seem to be stopping anyone, here's my entry.
8
9 Since the only alternative to a regexp presented so far was using python
10 (which has been considered a bit heavy-weight), I'll suggest some hacky
11 shell code instead (here as a one-liner, would probably be nicer to do this
12 as a function):
13
14 ---
15 [me@you ~]# ip=01.02.00.0004; for d in $(echo "${ip}"|tr '.' '\n');
16 do myip="${myip}"$(printf "%i" "${d}")"." ; done; echo ${myip%.}
17 1.2.0.4
18 ---
19
20
21 HTH
22 Gerrit

Replies