开发者

replacing dot in string, but leaving 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜