Replace multiple dots (.) with spaces ( )

Hi all,

I have files in the filename pattern of,

this.is.the.name.of.my.file.mov

and I would like to remove dots (.) and replace them with spaces ( ) so the output would be,

this is the name of my file.mov

The other issue that I have is that the number of dots (.) in the file name is dependent on how many words are in the name so will always be different i.e.

this.is.the.name.of.my.file.mov or

this.is.my.file.mov or

my.file.mov and so on...

Is it possible to use a script to replace the dots (.) with spaces ( ) leaving the .file extention on filenames with different character lengths?

I currently use this script to delete txt from filenames,

find . -type f | while read i;do [ "$i" != "${i//abc/}" ] && mv "$i" "${i//abc/}" ;done

but I don't think I can use it in this case.

Thanks in advance!!! :slight_smile:

Try this

echo "this.is.the.name.of.my.file.mov" | tr '.' ' ' | sed 's/\(.*\) \([^ ]*[aA-zZ][aA-zZ]*$\)/\1.\2/g'

o/p

this is the name of my file.mov
tr '.' ' ' < filename | sed 's/\(.*\) \([^ ]*[aA-zZ][aA-zZ]*$\)/\1.\2/g'

cheers,
Devaraj Takhellambam

Devaraj,

Thanks for the quick reply!

Sorry for asking a stupid question but do I run the tr script from terminal on a mac or save as a shell script.

Or something completely different

No worries. you can do either way. If you want to put it in shell script, then make sure that the file is in the same directory as the script .

It will be easier if you run it from the command prompt. just replace the filename with your file and then redirect the o/p to another file.

tr '.' ' ' < filename | sed 's/\(.*\) \([^ ]*[aA-zZ][aA-zZ]*$\)/\1.\2/g' > outfile

cheers,
Devaraj Takhellambam

Devaraj,

Ok I get it now...

Is there a way to not have to put in the filename? So the script changes any file in the folder that has a .mov extension?

tr '.' ' ' < *.mov | sed 's/\(.*\) \([^ ]*[aA-zZ][aA-zZ]*$\)/\1.\2/g' > outfile

Thanks (again).

put this in a script and run:

for file in *.mov
do
newname=`echo $file | tr '.' ' ' | sed 's/\(.*\) \([^ ]*[aA-zZ][aA-zZ]*$\)/\1.\2/g' `
mv "$file" "$newname"
done

cheers,
Devaraj Takhellambam

Devaraj,

WORKED PERFECTLY!!!!!

Thanks Again. :slight_smile: