How to Removing a dot from a file name?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Removing a dot from a file name?
# 1  
Old 09-13-2011
How to Removing a dot from a file name?

I need a script that will allow me to rename all of my files in subdir /FilesIn
as follows:


From kumc_835_111200.RMT.dat to kumc_835_111200RMT.dat
kumc_835_111200.KMR.dat to kumc_835_111200KMR.dat

.................etc


How do I do that whithout doing a sed 's/.RMT/RMT\g' since the file name is not always .RMT.DAT !!

Thanks
# 2  
Old 09-13-2011
Code:
ls | while read FILE
do
        IFS="."
        set -- $FILE
        if [ $# -eq 3 ]
        then
                echo mv "$FILE" "${1}${2}.${3}"
        fi
done

# 3  
Old 09-13-2011
Code:
rename 's/\.//' *.dat
 
rename 's/dat/\.dat/' *dat


Last edited by Franklin52; 09-14-2011 at 09:20 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 09-13-2011
Here is what have to rename:

from 082211001.RMT to Kum_082211001RMT.DAT

How do I do thaT. The filename may contact any character after the dot. not just .RMT

Thanks

---------- Post updated at 04:17 PM ---------- Previous update was at 04:13 PM ----------

Quote:
Originally Posted by mira
rename 's/\.//' *.dat

rename 's/dat/\.dat/' *dat


did not work
# 5  
Old 09-13-2011
Quote:
Originally Posted by mrn6430
Here is what have to rename:

from 082211001.RMT to Kum_082211001RMT.DAT

Code:
suffix=DAT
for file in *
do
  mv "$file" "${file%.*}.$suffix"
done

# 6  
Old 09-13-2011
do you want to add .DAT to all file names and remove all other dots?

your first example was showing that all your files are ending with .dat and you wish you remove all dots other than the one before dat.
# 7  
Old 09-13-2011
awk : (the ls or find cmd to get the file name is omitted)

Code:
kent$  echo "a.b.c.d.f.dat"|awk -F'.' 'BEGIN{OFS=""}{s=$NF;o=$0;$NF="";print "mv "o" " $0"."s}'                                          
mv a.b.c.d.f.dat abcdf.dat

add |sh at the end of the command line will do the rename.


kent$  echo "a.b.c.d.f.dat"|awk -F'.' 'BEGIN{OFS=""}{s=$NF;o=$0;$NF="";print "mv "o" " $0"."s}' |sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename except dot file extension

After reading the manual of the command rename I would like to apply it to a folder with a couple of files containing old style dots before the file-type, e.g. up.to.the.roof.avi. So I'd like to rename them without the dots in between. Therefore I tried it the following way rename -f -n ... (4 Replies)
Discussion started by: 1in10
4 Replies

2. Shell Programming and Scripting

How to remove. (dot) if found in the beginning of file name while doing wget (download)?

Dear All, How to remove. (dot) if found in the beginning of file name while doing wget (download)? I am facing problem while re-sizing the image by using ImageMagick. Two dots in the file name are causing problem. ImageMagick is skipping such image with a dot . in the beginning, like ... (1 Reply)
Discussion started by: Praveen Pandit
1 Replies

3. Shell Programming and Scripting

List the file with a dot

I am on hp-ux and not able to catch the file with dot using a wild card. $ touch .test $ ls -l .test -rw-r--r-- 1 oracle dba 0 Mar 21 05:20 .test $ ls -l *test *test not found $ ls -la *test *test not found Why i am not able to list the file startign with .... (7 Replies)
Discussion started by: bang_dba
7 Replies

4. Shell Programming and Scripting

grep'ing dot history file

Hi, I tried to grep ".sh_history" (DOTsh_history) file and did not return anything though I found the word in .sh _history file through vi editor in Linux. Then I tried to grep ".profile" to check if it is the prob with hidden files and I got results. Then I verified the same with my friend... (4 Replies)
Discussion started by: bobbygsk
4 Replies

5. Shell Programming and Scripting

removing a word in a multiple file starting at the dot extension

hi I would like to ask if someone knows a command or a script on how to rename a multiple file in the directory starting at the end of the filename or at the .extension( i would like to remove the last 11 character before the extension) for example Below is the result of my command ls inside... (5 Replies)
Discussion started by: jao_madn
5 Replies

6. Programming

how to call dot c file using system command

Hi every one, i have to dot pc files. One have main function but one dont have.I have to call dot pc file using system () cmd.File is being call have main function.Please let me know how i can call .pc file with two arguments from other dot pc file.I want some thing like sprintf(buf, "ss_xxx.pc... (4 Replies)
Discussion started by: goraya430
4 Replies

7. Shell Programming and Scripting

how to call dot c file using system command

Hi every one, i have to dot pc files. One have main function but one dont have.I have to call dot pc file using system () cmd.File is being call have main function.Please let me know how i can call .pc file with two arguments from other dot pc file.I want some thing like sprintf(buf,... (1 Reply)
Discussion started by: goraya430
1 Replies

8. Shell Programming and Scripting

use dot file in linux

Hi, I am creating a phonebook to store the name:phone:address.The phonebook is used to store, edit,delete and list the data. Now i need to use text file(dot files) for configuration (saving and loading selections). I really don't know how to do that. Please help thanks.. (6 Replies)
Discussion started by: coolgal
6 Replies

9. Shell Programming and Scripting

removing DOT by using perl

Hi Friends, I have a variable which has a number (e.g. 12.1234). I want to remove "." (dot) from that number i.e. 121234 I want to do this using perl. Can you please guide me Thank you Anushree (2 Replies)
Discussion started by: anushree.a
2 Replies

10. Shell Programming and Scripting

Replace path in a file with dot

Hi, I have a file with below values. /uvxapps/etl/Ascential/DataStage/DSEngine/dsenv.orig /uvxapps/etl/Ascential/DataStage/DSEngine/dsenv /uvxapps/etl/Ascential/DataStage/DSEngine/sample/.cshrc /uvxapps/etl/Ascential/DataStage/DSEngine/sample/.login... (3 Replies)
Discussion started by: njoshi
3 Replies
Login or Register to Ask a Question