Replace multiple dots (.) with spaces ( )


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace multiple dots (.) with spaces ( )
# 1  
Old 05-03-2009
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,

Code:
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!!! Smilie
# 2  
Old 05-03-2009
Try this

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

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

cheers,
Devaraj Takhellambam
# 3  
Old 05-03-2009
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
# 4  
Old 05-03-2009
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.

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


cheers,
Devaraj Takhellambam
# 5  
Old 05-03-2009
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?

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

Thanks (again).
# 6  
Old 05-03-2009
put this in a script and run:

Code:
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
# 7  
Old 05-03-2009
Devaraj,

WORKED PERFECTLY!!!!!

Thanks Again. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk gsub command to replace multiple spaces

Hi Forum. I'm trying to cleanup the following data elements (To remove any occurences of commas and any extra spaces) while preserving the <TAB> delimiter using awk gsub but I have not been successful. Original Data: 4365 monte des source rue,, ,<TAB>trevost<TAB>QC Desired Data:... (1 Reply)
Discussion started by: pchang
1 Replies

2. Shell Programming and Scripting

Replace white spaces of multiple files at once

How to rename multiple files by replacing the white spaces with underscore for ex: 293TrexFH\ \ \ GSM855007RINGB_lhb11_binary.txt 293TrexFH\ \ \ GSM855007RINGB_lhb12_binary.txt 293TrexFH\ \ \ GSM855007RINGB_lhb13_binary.txt 293TrexFH_GSM855007RINGB_lhb11_binary.txt... (1 Reply)
Discussion started by: quincyjones
1 Replies

3. Shell Programming and Scripting

Get file extension with multiple dots

I am trying to get the file extension with file names that could contain multiple dots using shell scripting. I want to find a way using the sed command. Example Filenames: one.dat one.dat.002 Results: dat I would like to return dat in both instances using the sed command. How can I... (4 Replies)
Discussion started by: smkremer
4 Replies

4. Shell Programming and Scripting

Remove filenames beginning with multiple dots

hi all, I want to remove filenames beginning with multiple dots.how I can do this. Thanks in advance (5 Replies)
Discussion started by: sriharsharavi
5 Replies

5. Shell Programming and Scripting

Replace with spaces

Hi Guys file:///C:/DOCUME%7E1/c104058/LOCALS%7E1/Temp/moz-screenshot.pngsed 's///g' /source/filename.txt > /destination/filename.txt The above code deletes the characters which are not A-Z, a-z and 0-9, but I wanted to replace it with space without deleting them. Any help is... (2 Replies)
Discussion started by: gowrishankar05
2 Replies

6. UNIX for Dummies Questions & Answers

how to replace spaces with '_' in a file?

Hello #I have a file with a list of sequences; the sequence name is the line starting with '>'. $cat infile >AluYa5 SINE1/7SL Homo sapiens ggccgggcgcggtggctcacgcctgtaatcccagcactttgggaggccgaggcgggcggatcacgaggtc aggagatcgagaccatcccggctaaaacggtgaaaccccgtctctactaaaaatacaaaaaattagccgg... (11 Replies)
Discussion started by: jdhahbi
11 Replies

7. Shell Programming and Scripting

replace 2 spaces by one

Dear Friends, I have a flat file from which I want to remove single "space". And, wherever two spaces are provided it should replace it by only one space. E.g. I have N A T I O N A L E D U C A T I O N F O R O R G AN I S A T I ON S I want NATIONAL EDUCATION FOR ORGANISATIONS Please... (5 Replies)
Discussion started by: anushree.a
5 Replies

8. Shell Programming and Scripting

Replace spaces

Hi guys, so I have another issue. Can I use sed to replace spaces in a string or variable with %20 I am having trouble with using curl on URL's containing spaces Thanks! (12 Replies)
Discussion started by: tret
12 Replies

9. Shell Programming and Scripting

Stripping out extensions when file has multiple dots in name

I posted this already in another thread, but was told that I should create a seperate thread for the following question: How do I strip the extension when the delimiter might occur multiple times in the filename? For example: I have 2 files as input for my script. test.extension... (8 Replies)
Discussion started by: Nemelis
8 Replies

10. Shell Programming and Scripting

Replace spaces recursively

Hi, I have a directory with files and sub-directories (sub-directory depth might go upto 5). There will be one or more spaces (continuously or anywhere in the file name) which need to be replaced with HYPHENs. How can i replace all SPACE occurances with HYPHEN in file/dir names recursively. (2... (5 Replies)
Discussion started by: prvnrk
5 Replies
Login or Register to Ask a Question