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.) |