1

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?

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.