Using SED with wildcard

前端 未结 2 611
粉色の甜心
粉色の甜心 2020-12-03 02:59

I want to replace a string with wildcard but it doesn\'t work.

The string looks like \"some-string-8\"

I wrote

sed -i \'s/string-*/string-0/g         


        
相关标签:
2条回答
  • 2020-12-03 03:28

    The asterisk (*) means "zero or more of the previous item".

    If you want to match any single character use

    sed -i 's/string-./string-0/g' file.txt
    

    If you want to match any string (i.e. any single character zero or more times) use

    sed -i 's/string-.*/string-0/g' file.txt
    
    0 讨论(0)
  • 2020-12-03 03:28

    So, the concept of a "wildcard" in Regular Expressions works a bit differently. In order to match "any character" you would use "." The "*" modifier means, match any number of times.

    0 讨论(0)
提交回复
热议问题