Renaming a file and keep the extension of file as it is


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming a file and keep the extension of file as it is
# 8  
Old 07-27-2011
No, all filenames in the folder matching to XX*.txt condtion like XXABC.txt, XXXYZ.txt etc. I hope now the requirement is clear to you?
# 9  
Old 07-27-2011
Code:
 
i=0
for file in XX*.txt
do 
   echo "$file"
   #echo $i
   i=`expr $i + 1`
   newName=`basename $file .txt`
  mv $src_dir/${file} $src_dir/${newName}_${i}.txt
done

# 10  
Old 07-27-2011
It can have many filenames matching to XX*.txt / XX*.dat conditions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. UNIX for Dummies Questions & Answers

File Extension Missing in file-$var.csv

I'm afraid this is a silly question but I can't figure it out. I have a script like so... echo "Enter DRDL Signature Version Number" read DRDL_Number mv signature_output.csv SERVICE_OBJECTS_S-$DRDL_Number.csv The resultant filename does not contain the .csv as follows.... (3 Replies)
Discussion started by: Cludgie
3 Replies

3. Shell Programming and Scripting

Renaming file and check for the renamed file existence

Hi Am trying to move a file from one name to another When I do "ls" to check for the moved filename I can see the file but when I try the same with a script am unable.. I think am doing some pretty silly error.. please help.. toMove=`ls | grep -E "partition.+"` mv $toMove partition._org... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

4. Shell Programming and Scripting

Renaming the extension of a set of files

Hi All, I am trying to rename the extension of a set of file from .txt to .xtx. When I run the following script, #!/bin/sh l=`ls /f` for f in $l do "mv $f ${f%.txt}.xtx" ; done a file such as 1.txt is renamed to 1? where ? is a strange character. Could you please help me fix the code... (3 Replies)
Discussion started by: sara123
3 Replies

5. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

6. Shell Programming and Scripting

File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile). The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
Discussion started by: netfreighter
7 Replies

7. Shell Programming and Scripting

bad substitution Error while renaming Extension

Hi All, We are in the process of Migrating from AIX 4 to Solaris 10 and getting a Few Errors. I have been programming in shell but could never establish muself as an expert, hence please need you help. I am Getting Bad Substitution error in my script, I have isolated the issue and its... (6 Replies)
Discussion started by: paragkhanore
6 Replies

8. Shell Programming and Scripting

Renaming a file use another file as a sequence calling a shl

have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using... (3 Replies)
Discussion started by: rechever
3 Replies

9. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

10. UNIX for Dummies Questions & Answers

Renaming multiple files, to get rid of extension

I have a good script to rename multiple files, but what's the best way I can remove some text from multiple filenames? Say I have a directory with 35 files with a .XLS at the end, how can I rename them to remove the .XLS but keep everything the same, without having to mv manually. Thanks. (6 Replies)
Discussion started by: nj78
6 Replies
Login or Register to Ask a Question