1 |
On 23/01/19 07:37, Alexander Kapshuk wrote: |
2 |
> On Wed, Jan 23, 2019 at 9:05 AM Paul Colquhoun |
3 |
> <paulcol@×××××××××××××××××.au> wrote: |
4 |
>> |
5 |
>> On Wednesday, 23 January 2019 5:52:57 PM AEDT Alexander Kapshuk wrote: |
6 |
>>> On Wed, Jan 23, 2019 at 5:20 AM Adam Carter <adamcarter3@×××××.com> wrote: |
7 |
>>>>>> François-Xavier |
8 |
>>>>> |
9 |
>>>>> My bad, it should be: |
10 |
>>>>> |
11 |
>>>>> sed 's/0*\([0-9][0-9]*\)/\1/g' |
12 |
>>>>> |
13 |
>>>>> (tests are indeed needed!) |
14 |
>>>> |
15 |
>>>> Many thanks François. This is almost right, but it is also stripping zeros |
16 |
>>>> that follow a letter, and I only want it to strip zeros that are |
17 |
>>>> proceeded by a period. There are no leading zeros in the first octet of |
18 |
>>>> the IP so that case does not need to be handled. |
19 |
>>>> |
20 |
>>>> Does the \1 refer to what's in the ()'s? So anything that one would wont |
21 |
>>>> to carry through should be inside the ()'s and anything that's outside is |
22 |
>>>> stripped, right? |
23 |
>>> Would something like to do the trick? |
24 |
>>> echo 198.088.062.01 | sed 's/\.0/./g' |
25 |
>>> 198.88.62.1 |
26 |
>> |
27 |
>> In a word, no. |
28 |
>> |
29 |
>> echo 198.088.0.01 | sed 's/\.0/./g' |
30 |
>> 198.88..1 |
31 |
>> |
32 |
>> |
33 |
>> -- |
34 |
>> Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/ |
35 |
>> Asking for technical help in newsgroups? Read this first: |
36 |
>> http://catb.org/~esr/faqs/smart-questions.html#intro |
37 |
>> |
38 |
>> |
39 |
>> |
40 |
>> |
41 |
> |
42 |
> How about this one? |
43 |
> |
44 |
> echo '198.088.0.01 |
45 |
> 198.088.062.01' | sed 's/\.0\([0-9][0-9]*\)/.\1/g' |
46 |
> 198.88.0.1 |
47 |
> 198.88.62.1 |
48 |
> |
49 |
|
50 |
I've just done a bit of digging, and would this work to match an octet? |
51 |
|
52 |
[0-9][0-9]?[0-9]? |
53 |
|
54 |
I know ? normally matches a single character, but apparently in this |
55 |
syntax it means "0 or 1 occurrence of the preceding expression". So that |
56 |
will detect a number consisting of at most three digits. |
57 |
|
58 |
I thought there must be a "detect a single optional character" operator |
59 |
... :-) |
60 |
|
61 |
Cheers, |
62 |
Wol |