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.

link|improve this question
feedback

2 Answers

up vote 1 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.

link|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
feedback

Using bash:

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

Using zsh:

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

Your Answer

 
or
required, but never shown

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