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?
# 8  
Old 09-14-2011
Quote:
Originally Posted by cfajohnson
Code:
suffix=DAT
for file in *
do
  mv "$file" "${file%.*}.$suffix"
done


It does not work. It partially works. Here is what I have:
Code:
for file in 08261100.RMT
do
  newfile=`echo kumc_835_Aetna_${file%.*}.dat`

  mv $file ./$newfile
done

It comes out as : kumc_835_Aetna_08261100.dat
I need it to write it as: kumc_835_Aetna_08261100RMT.dat

I need to remove the . from the input file "keep the old extention " and add .dat to the end.

Thanks

---------- Post updated at 09:22 PM ---------- Previous update was at 05:03 PM ----------

Quote:
Originally Posted by mira
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.


Yes.

---------- Post updated at 09:32 PM ---------- Previous update was at 09:22 PM ----------

Quote:
Originally Posted by sk1418
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


Thank you, I will try it tomorrow when I am at the office. Can you please explain to me what each part mean/does. Thanks

Last edited by Franklin52; 09-15-2011 at 04:19 AM.. Reason: Please use code tags for code and data samples, thank you
# 9  
Old 09-14-2011
Save the file under the location where you need to rename files and run
Code:
#!/bin/ksh
ls *.dat | while read file
do
        mv $file ${file/./}
done

# 10  
Old 09-14-2011
Quote:
Originally Posted by mrn6430


Thank you, I will try it tomorrow when I am at the office. Can you please explain to me what each part mean/does. Thanks
a.b.c.d.f.dat is the file name you want to play with.
the awk line produces the shell command "mv a.b.c.d.f.dat abcdef.dat"
|sh will execute the command, to do the rename operation.
# 11  
Old 09-14-2011
MySQL Final version that worked - thanks to all

Thank you all for your valuable information. Here is the final version I used that works for what I want. I used 2 for loops as follows in my script:
Code:
for file in $GetFileName*.*; do
     newfile=`echo kumc_835_Aetna_$file.dat`
     mv $file ./$newfile
done
for file in kumc_835_Aetna*.dat; do
     newfile=`echo $file | awk -F'.' 'BEGIN{OFS=""}{s=$NF;o=$0;$NF="";print "mv "o" " $0"."s}'|sh`
done


Thanks again

Last edited by Franklin52; 09-15-2011 at 04:19 AM.. Reason: Please use code tags for code and data samples, thank you
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