Gentoo Archives: gentoo-user

From: Alexander Kapshuk <alexander.kapshuk@×××××.com>
To: Gentoo mailing list <gentoo-user@l.g.o>
Subject: Re: [gentoo-user] OT scripting - strip zero if between period and digit
Date: Wed, 23 Jan 2019 07:38:19
Message-Id: CAJ1xhMXiK_PuVKMf=7xjc=OE2sEw=LtJEKN86DeZ8sduN5ccHQ@mail.gmail.com
In Reply to: Re: [gentoo-user] OT scripting - strip zero if between period and digit by Paul Colquhoun
1 On Wed, Jan 23, 2019 at 9:05 AM Paul Colquhoun
2 <paulcol@×××××××××××××××××.au> wrote:
3 >
4 > On Wednesday, 23 January 2019 5:52:57 PM AEDT Alexander Kapshuk wrote:
5 > > On Wed, Jan 23, 2019 at 5:20 AM Adam Carter <adamcarter3@×××××.com> wrote:
6 > > >> > François-Xavier
7 > > >>
8 > > >> My bad, it should be:
9 > > >>
10 > > >> sed 's/0*\([0-9][0-9]*\)/\1/g'
11 > > >>
12 > > >> (tests are indeed needed!)
13 > > >
14 > > > Many thanks François. This is almost right, but it is also stripping zeros
15 > > > that follow a letter, and I only want it to strip zeros that are
16 > > > proceeded by a period. There are no leading zeros in the first octet of
17 > > > the IP so that case does not need to be handled.
18 > > >
19 > > > Does the \1 refer to what's in the ()'s? So anything that one would wont
20 > > > to carry through should be inside the ()'s and anything that's outside is
21 > > > stripped, right?
22 > > Would something like to do the trick?
23 > > echo 198.088.062.01 | sed 's/\.0/./g'
24 > > 198.88.62.1
25 >
26 > In a word, no.
27 >
28 > echo 198.088.0.01 | sed 's/\.0/./g'
29 > 198.88..1
30 >
31 >
32 > --
33 > Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/
34 > Asking for technical help in newsgroups? Read this first:
35 > http://catb.org/~esr/faqs/smart-questions.html#intro
36 >
37 >
38 >
39 >
40
41 How about this one?
42
43 echo '198.088.0.01
44 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g'
45 198.88.0.1
46 198.88.62.1

Replies

Subject Author
Re: [gentoo-user] OT scripting - strip zero if between period and digit Wols Lists <antlists@××××××××××××.uk>
[gentoo-user] Re: OT scripting - strip zero if between period and digit Grant Edwards <grant.b.edwards@×××××.com>