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 |