Replacing multiple asterisks in vi

i need to replace all occurrences of "period asterisk" as it is shown in this:

blah blah .*:.*:.* blah blah 

with:

[0-9][0-9]:[0-9][0-9]:[0-9][0-9]

so that the end result looks like this:

blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah

I tried different variations of the following but it didint work:

%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g

Hi,

I just tried this in vim , and the following command worked for me:

1,$ s/\.\*/[0-9][0-9]/g

This turned the following string:

blah blah .*:.*:.* blah blah

into this:

blah blah [0-9][0-9]:[0-9][0-9]:[0-9][0-9] blah blah

Caveats: this was a quick one-liner in vim for iOS, so your mileage may vary as they say. But this appears to work for this very specific string in these very specific circumstances.

1 Like

I think this works in all vi and vim variants and in all OSes.
Further it works in all sed versions, where the 1,$ (all lines) selector can be omitted because it is default.