开发者

replacing dot in string, but leaving last one

开发者 https://www.devze.com 2023-02-04 22:21 出处:网络
replace the \".\" [dots], but leave the last one: e.g.: .txt [there could be ran开发者_开发百科dom number of dots in the string, even zero, i just need the last one]

replace the "." [dots], but leave the last one: e.g.: .txt [there could be ran开发者_开发百科dom number of dots in the string, even zero, i just need the last one]

$ echo 'someth.ing.something.txt' | SOMEMAGIC
someth-ing-something.txt


$ echo 'toto.tata.titi.' | sed 's/\.\([^$]\)/-\1/g'
toto-tata-titi.


echo 'someth.ing.something.txt' | sed 's/\./-/g' | sed 's/-\([^-]*$\)/.\1/g'


basename one.two.three.txt .txt | sed -e 's/.//g' -e 's/$/.txt/'


In sed, with recursive substitutions:

sed ':a /\..*\./ {s/\./-/}; t a'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号