Hyphen and underscore not compatible in sed

前端 未结 4 2105
傲寒
傲寒 2021-01-18 15:39

I\'m having trouble getting sed to recognize both hyphen and underscore in its pattern string.

Does anyone know why

[a-z|A-Z|0-9|\\-|_]
4条回答
  •  时光取名叫无心
    2021-01-18 16:22

    In my case, I wanted to replace a config setting that included a hyphen. Surrounding the setting in .* worked:

    sed 's/.*some-service.*/some-service="new-value"/g' file
    

    Also works when the config setting has an underscore.

提交回复
热议问题