sed plus sign doesn't work

后端 未结 4 1442
你的背包
你的背包 2020-12-01 15:53

I\'m trying to replace /./ or /././ or /./././ to / only in bash script. I\'ve managed to create regex for sed but it doe

4条回答
  •  一生所求
    2020-12-01 16:08

    Two things to make it simple:

    $ variable="something/./././"
    $ sed -r 's#(\./){1,}##' <<< "$variable"
    something/
    
    • Use {1,} to indicate one or more patterns. You won't need g with this.
    • Use different delimiterers # in above case to make it readable
    • + is ERE so you need to enable -E or -r option to use it

提交回复
热议问题