Gentoo Archives: gentoo-user

From: "François-Xavier CARTON" <fx.carton@×××××.fr>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT scripting - strip zero if between period and digit
Date: Tue, 22 Jan 2019 02:15:07
Message-Id: 8fe24c6a-6b08-b341-d269-4f9eb43f49cb@yahoo.fr
In Reply to: Re: [gentoo-user] OT scripting - strip zero if between period and digit by "François-Xavier CARTON"
1 Le 22/01/2019 à 03:05, François-Xavier CARTON a écrit :
2 > Le 22/01/2019 à 00:50, Adam Carter a écrit :
3 >> I need to clean up a file which has IP addresses with leading zeros in
4 >> some of the octets so I need to make, say, .09 into .9
5 >>
6 >> How do i do that in sed/awk/whatever?
7 >
8 >
9 > I believe that should do:
10 >
11 > sed 's/0*\([0-9]\)/\1/g'
12 >
13 > eg.
14 >
15 > $ sed 's/0*\([0-9]\)/\1/g' <<EOF
16 > 0.1.2.3
17 > 01.2.3.4
18 > 1.2.3.0
19 > 1.2.000.3
20 > EOF
21 > 0.1.2.3
22 > 1.2.3.4
23 > 1.2.3.0
24 > 1.2.0.3
25 >
26 > François-Xavier
27 >
28 >
29
30 My bad, it should be:
31
32 sed 's/0*\([0-9][0-9]*\)/\1/g'
33
34 (tests are indeed needed!)
35
36 François-Xavier

Replies

Subject Author
Re: [gentoo-user] OT scripting - strip zero if between period and digit Adam Carter <adamcarter3@×××××.com>