Replacing .* in vi
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I need to replace all occurrences of "period asterisk" as it is shown here:
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 didn't work:
%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g
sed regular-expression vi
add a comment |Â
up vote
2
down vote
favorite
I need to replace all occurrences of "period asterisk" as it is shown here:
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 didn't work:
%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g
sed regular-expression vi
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I need to replace all occurrences of "period asterisk" as it is shown here:
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 didn't work:
%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g
sed regular-expression vi
I need to replace all occurrences of "period asterisk" as it is shown here:
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 didn't work:
%s_ .*:.*:.* _ [0-9][0-9]:[0-9][0-9]:[0-9][0-9] _g
sed regular-expression vi
sed regular-expression vi
edited Oct 19 '17 at 10:19
Kusalananda
106k14209327
106k14209327
asked Sep 24 '17 at 23:20
swenson
112
112
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g
For sed
: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'
.
%
means apply the substitution on all lines; is not needed insed
where by default the command is applied to all lines..
is a period; a bare.
means any character.*
is an asterisk; a bare*
means 0 or more of the preceding atom.
add a comment |Â
up vote
2
down vote
You gave an example of a line with âÂÂperiod asteriskâ repeated three times,
separated by colons.ÃÂ
If your data will always look like that, you might as well stick
with AlexPâÂÂs answer.ÃÂ
But your question says
that you need to replace all occurrences of âÂÂperiod asteriskâÂÂ.ÃÂ
If that statement of the problem is accurate, you should use
:%s/.*/[0-9][0-9]/g
which will find and replace âÂÂperiod asteriskâÂÂ
even when it doesnâÂÂt appear in groups of three.
add a comment |Â
up vote
0
down vote
Using the nomagic
modifier for the pattern in Vim:
:%s/M.*/[0-9][0-9]/g
The M
will remove the specialness of both .
and *
in the pattern.
See :help magic
in Vim.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g
For sed
: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'
.
%
means apply the substitution on all lines; is not needed insed
where by default the command is applied to all lines..
is a period; a bare.
means any character.*
is an asterisk; a bare*
means 0 or more of the preceding atom.
add a comment |Â
up vote
2
down vote
For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g
For sed
: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'
.
%
means apply the substitution on all lines; is not needed insed
where by default the command is applied to all lines..
is a period; a bare.
means any character.*
is an asterisk; a bare*
means 0 or more of the preceding atom.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g
For sed
: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'
.
%
means apply the substitution on all lines; is not needed insed
where by default the command is applied to all lines..
is a period; a bare.
means any character.*
is an asterisk; a bare*
means 0 or more of the preceding atom.
For Vim: :%s/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g
For sed
: sed -e 's/.*:.*:.*/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/g'
.
%
means apply the substitution on all lines; is not needed insed
where by default the command is applied to all lines..
is a period; a bare.
means any character.*
is an asterisk; a bare*
means 0 or more of the preceding atom.
answered Sep 24 '17 at 23:38
AlexP
6,656924
6,656924
add a comment |Â
add a comment |Â
up vote
2
down vote
You gave an example of a line with âÂÂperiod asteriskâ repeated three times,
separated by colons.ÃÂ
If your data will always look like that, you might as well stick
with AlexPâÂÂs answer.ÃÂ
But your question says
that you need to replace all occurrences of âÂÂperiod asteriskâÂÂ.ÃÂ
If that statement of the problem is accurate, you should use
:%s/.*/[0-9][0-9]/g
which will find and replace âÂÂperiod asteriskâÂÂ
even when it doesnâÂÂt appear in groups of three.
add a comment |Â
up vote
2
down vote
You gave an example of a line with âÂÂperiod asteriskâ repeated three times,
separated by colons.ÃÂ
If your data will always look like that, you might as well stick
with AlexPâÂÂs answer.ÃÂ
But your question says
that you need to replace all occurrences of âÂÂperiod asteriskâÂÂ.ÃÂ
If that statement of the problem is accurate, you should use
:%s/.*/[0-9][0-9]/g
which will find and replace âÂÂperiod asteriskâÂÂ
even when it doesnâÂÂt appear in groups of three.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You gave an example of a line with âÂÂperiod asteriskâ repeated three times,
separated by colons.ÃÂ
If your data will always look like that, you might as well stick
with AlexPâÂÂs answer.ÃÂ
But your question says
that you need to replace all occurrences of âÂÂperiod asteriskâÂÂ.ÃÂ
If that statement of the problem is accurate, you should use
:%s/.*/[0-9][0-9]/g
which will find and replace âÂÂperiod asteriskâÂÂ
even when it doesnâÂÂt appear in groups of three.
You gave an example of a line with âÂÂperiod asteriskâ repeated three times,
separated by colons.ÃÂ
If your data will always look like that, you might as well stick
with AlexPâÂÂs answer.ÃÂ
But your question says
that you need to replace all occurrences of âÂÂperiod asteriskâÂÂ.ÃÂ
If that statement of the problem is accurate, you should use
:%s/.*/[0-9][0-9]/g
which will find and replace âÂÂperiod asteriskâÂÂ
even when it doesnâÂÂt appear in groups of three.
answered Sep 25 '17 at 5:01
Scott
6,30742448
6,30742448
add a comment |Â
add a comment |Â
up vote
0
down vote
Using the nomagic
modifier for the pattern in Vim:
:%s/M.*/[0-9][0-9]/g
The M
will remove the specialness of both .
and *
in the pattern.
See :help magic
in Vim.
add a comment |Â
up vote
0
down vote
Using the nomagic
modifier for the pattern in Vim:
:%s/M.*/[0-9][0-9]/g
The M
will remove the specialness of both .
and *
in the pattern.
See :help magic
in Vim.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using the nomagic
modifier for the pattern in Vim:
:%s/M.*/[0-9][0-9]/g
The M
will remove the specialness of both .
and *
in the pattern.
See :help magic
in Vim.
Using the nomagic
modifier for the pattern in Vim:
:%s/M.*/[0-9][0-9]/g
The M
will remove the specialness of both .
and *
in the pattern.
See :help magic
in Vim.
answered Oct 19 '17 at 10:16
Kusalananda
106k14209327
106k14209327
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394213%2freplacing-in-vi%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password