how to rename a number of files


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
how to rename a number of files

Hi
I need to rename about hundred of files which contain ".R " and the end, for example:
/t1/data/f2993trn.ix7.R
The new file should not have ".R" extension, ex:
/t1/data/f2993trn.ix7.R

Is there a command which I can put in the loop to do this? Thansk for any advice -A
# 2  
Code:
cat your_list_of_files |
while read file_nm ; do

  echo /bin/mv $file_nm ${$file_nm%.*}

done

save that in a script.
run it.
if it looks good, pipe it to /bin/ksh:

Code:
quirks_script | /bin/ksh

and voila.
# 3  
Not sure if ${$file_nm%.*} will give you grief but you can do this:

Code:
ls *.R 2>/dev/null|while read file_nm ; do
 echo mv $file_nm ${file_nm%.*}
done

Then do what quirkasaurus said to check and then run.
# 4  
no need ls in fact
Code:
for file in *.R
do
....
done

# 5  
Quote:
Originally Posted by giannicello
Code:
ls *.R 2>/dev/null|while read file_nm ; do
 echo mv $file_nm ${file_nm%.*}
done


Not only is ls unnecessary, but it will break the script if any filenames contain spaces.

The filenames should be quoted:
Code:
for file in *.R ; do
 echo mv "$file" "${file%.R}"
done

# 6  
Not sure about Unix flavors, but if you have Linux, then you don't even need a loop. The rename command can fix the file names.

Code:
$
$ uname -o
GNU/Linux
$
$ ls -1
file1.R
file2.R
file3.R
file4.R
file5.R
file 6.R
$
$ rename .R '' *.R
$
$ ls -1
file1
file2
file3
file4
file5
file 6
$
$

HTH,
tyler_durden
# 7  
Quote:
Originally Posted by durden_tyler
Not sure about Unix flavors, but if you have Linux, then you don't even need a loop. The rename command can fix the file names.

There are two different versions of rename in Linux distributions, and the syntax is not the same for both. If you have a rename command, check the man page for the correct syntax.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #246
Difficulty: Easy
By 1973, e-mail constituted 95% of the ARPANET traffic.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

3. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

4. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

5. UNIX for Dummies Questions & Answers

Rename a large number of files in subdirectories

Hi, I have a large number of subdirectories (>200), and in each of these directories there is a file with a name like "opp1234.dat". I'd like to know how I could change the names of these files to say "out.dat" in all these subdirectories in one go. Thanks! (5 Replies)
Discussion started by: lost.identity
5 Replies

6. UNIX for Dummies Questions & Answers

Rename several files

Hi, I would like to rename several files, for example: MSIRP_CatastropheLog_Data_Extract_-_TCAPMI_SMB_20111116_040028.txt MSIRP_CatastropheLog_Data_Extract_-_TCAPMI_SMB_20111117_040023.txt MSIRP_CatastropheLog_Data_Extract_-_TCAPMI_SMB_20111118_040039.txt... (3 Replies)
Discussion started by: wsoethe
3 Replies

7. Shell Programming and Scripting

Rename files

I wrote a script that accepts filenames as argument but I am having difficulty if filename has both(uper/lower) cases..so I want to write a script that accepts one or more filenames as arguments and converts filenames to uppercase..(actually rename files..) (2 Replies)
Discussion started by: aadi_uni
2 Replies

8. Shell Programming and Scripting

rename files Ax based on strings found in files Bx

Hi, I'm not very experienced in shell scripting and that's probably why I came across the following problem: I do have several hundred pairs of text files (PF00x.spl and PF00x.shd) where the first file (PF00x.spl) needs to be renamed according a string that is included in the second file... (12 Replies)
Discussion started by: inCH
12 Replies

9. Shell Programming and Scripting

Rename many files

Hi all I have files in the following format: 01_anote1.pdf 01_bnote1.pdf 01_control1.pdf 01_ethics1.pdf 01_invoice1.pdf 01_invoice_21.pdf 20_quote_l1.pdf I need to rename them to 01_anote.pdf 01_bnote.pdf 01_control.pdf 01_ethics.pdf 01_invoice.pdf (9 Replies)
Discussion started by: lmatlebyane
9 Replies

10. UNIX for Dummies Questions & Answers

Rename a number of files using grep

Hi all, I'm trying to rename a directory of html-files: index.php?page=start should become start.html I've lost track of all the pipes and brackets and decided I need some help ;-) Many thanks. (4 Replies)
Discussion started by: TylerDurden
4 Replies

Featured Tech Videos