Gentoo Archives: gentoo-user

From: Michael Orlitzky <mjo@g.o>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT scripting - strip zero if between period and digit
Date: Tue, 22 Jan 2019 00:02:50
Message-Id: 9a929ddb-57db-1a02-e1f7-2db564fe9f1f@gentoo.org
In Reply to: [gentoo-user] OT scripting - strip zero if between period and digit by Adam Carter
1 On 1/21/19 6:50 PM, Adam Carter wrote:
2 > I need to clean up a file which has IP addresses with leading zeros in
3 > some of the octets so I need to make, say, .09 into .9
4 >
5 > How do i do that in sed/awk/whatever?
6
7 The first thing you should do is construct a bunch of test cases, with
8 all of the possible input representations and what you think the output
9 representation should be. Then, you should write a program in something
10 other than bash that passes all of the test cases. It's not as easy as
11 it sounds; for example:
12
13 * What happens to 0.1.2.3?
14
15 * What happens to 01.2.3.4?
16
17 * What happens to 1.2.3.0?
18
19 * What happens to 1.2.000.3?
20
21 You need a parser, not a regular expression. (You can do it with a
22 regex, but it's going to be one of those comical twelve-page-long things.)

Replies

Subject Author
Re: [gentoo-user] OT scripting - strip zero if between period and digit Grant Taylor <gtaylor@×××××××××××××××××××××.net>
Re: [gentoo-user] OT scripting - strip zero if between period and digit David Haller <gentoo@×××××××.de>