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.

I want to rename files as to delete unneccessary dots. ie:

File.something.jpg -> Filesomething.jpg
I.Have.Too.Many.Dots.png -> IHaveTooManyDots.png

How can this be done? find -name *.*.* lists them all, but I've been unable to write an expression for sed as it doesn't support lazy regexes.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Give this a try:

sed ':a;s/\.\([^.]\+\)\./\1./;ta' 

You could use it like this:

find -name "*.*.*" | xargs -I % bash -c 'mv "%" "$(echo "%" | sed "s|^./||;:a;s/\.\([^.]\+\)\./\1./;ta")"'

It's been sprinkled liberally with quotes so it should work with filenames that include spaces.

share|improve this answer
    
Worked, put all files in my current dir though >:(. Thanks anyways –  Robus Sep 14 '10 at 19:30
    
@Robus: Did you use the version with basename? That was a mistake. Sorry about that. The revised version shouldn't move files from subdirectories to the current directory. –  Dennis Williamson Sep 14 '10 at 19:33

Using bash:

find . -name '*.*.*' -exec bash -c 'base=${0##*/}; base=${base%.*}; mv "$0" "${0%/*}/${base//./}.${0##*.}"' {} \;

Using zsh:

autoload zmv
zmv '(**/)(*).(*)' '$1${2//./}.$3'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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