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'
精彩评论