Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
replacing dot in string, but leaving last one

replace the "." [dots], but leave the last one: e.g.: .txt [there could be random number of dots in the string, even zero, i just need the last one]

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

share|improve this question

migrated from serverfault.com Jan 17 '11 at 19:38

This question came from our site for professional system and network administrators.

marked as duplicate by DMA57361, Benjamin Bannier, Nifle, BloodPhilia, grawity Jan 17 '11 at 21:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Cross-posted on SuperUser: superuser.com/questions/234314/… –  Bobby Jan 17 '11 at 16:01
add comment

1 Answer

$ file='someth.ing.something.txt'
$ ext=${file##*.}
$ base=${file%.$ext}
$ echo $base
someth.ing.something
$ temp=${base//./-}
$ echo $temp
someth-ing-something
$ newfile=${temp}.${ext}
$ echo $newfile
someth-ing-something.txt
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.