How do I use wildcard containing conditional pattern during sed substitution?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
The following commands work.
sed -i "/BC_CD23.BC_B.BC_A1.N1_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
sed -i "/BC_CD23.BC_B.BC_A1.N0_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
This command doesn't work.
sed -i "/BC_CD23.BC_B.BC_A1.N*_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
How do I use wildcards in patterns?
sed regular-expression
add a comment |Â
up vote
1
down vote
favorite
The following commands work.
sed -i "/BC_CD23.BC_B.BC_A1.N1_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
sed -i "/BC_CD23.BC_B.BC_A1.N0_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
This command doesn't work.
sed -i "/BC_CD23.BC_B.BC_A1.N*_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
How do I use wildcards in patterns?
sed regular-expression
1
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used insed
(orgrep
and others). You should perhaps read an introduction.
â Philippos
Nov 6 '17 at 8:05
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The following commands work.
sed -i "/BC_CD23.BC_B.BC_A1.N1_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
sed -i "/BC_CD23.BC_B.BC_A1.N0_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
This command doesn't work.
sed -i "/BC_CD23.BC_B.BC_A1.N*_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
How do I use wildcards in patterns?
sed regular-expression
The following commands work.
sed -i "/BC_CD23.BC_B.BC_A1.N1_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
sed -i "/BC_CD23.BC_B.BC_A1.N0_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
This command doesn't work.
sed -i "/BC_CD23.BC_B.BC_A1.N*_C/s/CELL4WL_4BL_3/CELL4WL_4BL_1/g" s1*M8*
How do I use wildcards in patterns?
sed regular-expression
edited Nov 6 '17 at 14:26
Philippos
5,92211546
5,92211546
asked Nov 6 '17 at 6:48
Roopak Vasa
336
336
1
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used insed
(orgrep
and others). You should perhaps read an introduction.
â Philippos
Nov 6 '17 at 8:05
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18
add a comment |Â
1
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used insed
(orgrep
and others). You should perhaps read an introduction.
â Philippos
Nov 6 '17 at 8:05
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18
1
1
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used in
sed
(or grep
and others). You should perhaps read an introduction.â Philippos
Nov 6 '17 at 8:05
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used in
sed
(or grep
and others). You should perhaps read an introduction.â Philippos
Nov 6 '17 at 8:05
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
how to use wild card in pattern
In your particular case, N*
means "match N
char zero or more times".
If the pattern implies single N
char and one(or more) following digits - that pattern part should be N[0-9]1,
.
Besides, .
(period) char matches any character, including newline (though newlines won't occur in the input here). To be matched literally it should be escaped .
Thereupon, the main pattern would look as /BC_CD23.BC_B.BC_A1.N[0-9]1,_C/
https://www.gnu.org/software/sed/manual/sed.html#Overview-of-basic-regular-expression-syntax
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so,7
is between zero and seven times and, as in your question,1,
is one or more times. Somesed
versions have the shortcut+
for that.
â Philippos
Nov 12 '17 at 16:34
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
how to use wild card in pattern
In your particular case, N*
means "match N
char zero or more times".
If the pattern implies single N
char and one(or more) following digits - that pattern part should be N[0-9]1,
.
Besides, .
(period) char matches any character, including newline (though newlines won't occur in the input here). To be matched literally it should be escaped .
Thereupon, the main pattern would look as /BC_CD23.BC_B.BC_A1.N[0-9]1,_C/
https://www.gnu.org/software/sed/manual/sed.html#Overview-of-basic-regular-expression-syntax
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so,7
is between zero and seven times and, as in your question,1,
is one or more times. Somesed
versions have the shortcut+
for that.
â Philippos
Nov 12 '17 at 16:34
add a comment |Â
up vote
2
down vote
accepted
how to use wild card in pattern
In your particular case, N*
means "match N
char zero or more times".
If the pattern implies single N
char and one(or more) following digits - that pattern part should be N[0-9]1,
.
Besides, .
(period) char matches any character, including newline (though newlines won't occur in the input here). To be matched literally it should be escaped .
Thereupon, the main pattern would look as /BC_CD23.BC_B.BC_A1.N[0-9]1,_C/
https://www.gnu.org/software/sed/manual/sed.html#Overview-of-basic-regular-expression-syntax
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so,7
is between zero and seven times and, as in your question,1,
is one or more times. Somesed
versions have the shortcut+
for that.
â Philippos
Nov 12 '17 at 16:34
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
how to use wild card in pattern
In your particular case, N*
means "match N
char zero or more times".
If the pattern implies single N
char and one(or more) following digits - that pattern part should be N[0-9]1,
.
Besides, .
(period) char matches any character, including newline (though newlines won't occur in the input here). To be matched literally it should be escaped .
Thereupon, the main pattern would look as /BC_CD23.BC_B.BC_A1.N[0-9]1,_C/
https://www.gnu.org/software/sed/manual/sed.html#Overview-of-basic-regular-expression-syntax
how to use wild card in pattern
In your particular case, N*
means "match N
char zero or more times".
If the pattern implies single N
char and one(or more) following digits - that pattern part should be N[0-9]1,
.
Besides, .
(period) char matches any character, including newline (though newlines won't occur in the input here). To be matched literally it should be escaped .
Thereupon, the main pattern would look as /BC_CD23.BC_B.BC_A1.N[0-9]1,_C/
https://www.gnu.org/software/sed/manual/sed.html#Overview-of-basic-regular-expression-syntax
edited Nov 6 '17 at 8:17
answered Nov 6 '17 at 6:55
RomanPerekhrest
22.5k12145
22.5k12145
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so,7
is between zero and seven times and, as in your question,1,
is one or more times. Somesed
versions have the shortcut+
for that.
â Philippos
Nov 12 '17 at 16:34
add a comment |Â
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so,7
is between zero and seven times and, as in your question,1,
is one or more times. Somesed
versions have the shortcut+
for that.
â Philippos
Nov 12 '17 at 16:34
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
While your answer is perfectly correct and complete, I'm afraid that someone asking such a question has never heard of regular expressions and needs to be taught some basics to avoid being completely confused by this information.
â Philippos
Nov 6 '17 at 8:10
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
Thanks a lot. What does "1," mean in regex ?
â Roopak Vasa
Nov 12 '17 at 14:21
@RoopakVasa,
i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
@RoopakVasa,
i As *, but matches exactly i sequences (i is a decimal integer; for portability, keep it between 0 and 255 inclusive).
â RomanPerekhrest
Nov 12 '17 at 14:53
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so ,7
is between zero and seven times and, as in your question, 1,
is one or more times. Some sed
versions have the shortcut +
for that.â Philippos
Nov 12 '17 at 16:34
4,7
is for minimum 4 times, maximum 7 times the expression before. You can leave away either value, so ,7
is between zero and seven times and, as in your question, 1,
is one or more times. Some sed
versions have the shortcut +
for that.â Philippos
Nov 12 '17 at 16:34
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%2f402774%2fhow-do-i-use-wildcard-containing-conditional-pattern-during-sed-substitution%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
1
There is a difference between wildcards as used in file name matching/shell globbing and the much more powerful regular expressions as used in
sed
(orgrep
and others). You should perhaps read an introduction.â Philippos
Nov 6 '17 at 8:05
Thanks. I went through the link. I need to study regex in more detail .
â Roopak Vasa
Nov 12 '17 at 14:18