How do I use wildcard containing conditional pattern during sed substitution?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question


















  • 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










  • Thanks. I went through the link. I need to study regex in more detail .
    – Roopak Vasa
    Nov 12 '17 at 14:18














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?







share|improve this question


















  • 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










  • Thanks. I went through the link. I need to study regex in more detail .
    – Roopak Vasa
    Nov 12 '17 at 14:18












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?







share|improve this question














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?









share|improve this question













share|improve this question




share|improve this question








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 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












  • 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










  • 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










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






share|improve this answer






















  • 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. Some sed versions have the shortcut + for that.
    – Philippos
    Nov 12 '17 at 16:34










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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






share|improve this answer






















  • 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. Some sed versions have the shortcut + for that.
    – Philippos
    Nov 12 '17 at 16:34














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






share|improve this answer






















  • 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. Some sed versions have the shortcut + for that.
    – Philippos
    Nov 12 '17 at 16:34












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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








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. Some sed 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










  • 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. Some sed 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?