Renaming hundreds of files at the same time


 
Thread Tools Search this Thread
Operating Systems Solaris Renaming hundreds of files at the same time
# 1  
Old 10-25-2012
Renaming hundreds of files at the same time

Hi,

I am having issues trying to figure out how to rename files like this:

TEST1_B.tt

To

SQP_CAN_B.tt

I have hundreds of files like those, I need to rename them automatically.
Any help will be greatly appreciated.
Thanks,
# 2  
Old 10-25-2012
Can you please list out some 5-10 file names, we just want to find a pattern and see how a code can be written to rename them all?

Last edited by Yoda; 10-25-2012 at 07:20 PM..
# 3  
Old 10-25-2012
Samples:

TEST1_B.tt
TEST1_B.txt
TEST1_B.tif
TEST1_B.mt
TEST1_B.q
TEST1_B.delta

I need them to be like:
Mar_L.tt
Mar_L.txt
Mar_L.tif
Mar_L.mt
Mar_L.q
Mar_L.delta

Thanks
# 4  
Old 10-25-2012
Code:
for i in TEST1_B.*
do
 echo mv "$i" "Mar_L.${i/#*.}"
done

Remove the echo if the mv command lines seem alright.

Last edited by elixir_sinari; 10-26-2012 at 03:05 AM..
This User Gave Thanks to elixir_sinari For This Post:
# 5  
Old 10-26-2012
That is a good one, but.. what does it happen if the files are in multiple folders and subfolders?
# 6  
Old 10-26-2012
Then you have to use find instead:-

Code:
for i in `find . -name "TEST1_B*"`

Note: But if you want to rename these files in their respective directories, you have to get the path of each files and provide it in the mv command.

Last edited by Yoda; 10-26-2012 at 12:50 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hundreds of files need manual preparation. Does shell script could do it automatically?

Hello friends, I have hundreds files in hand, which need extract some data from logs and read these data into an input file. Here I will explain in detail using these two files as attached. read some data from .log file and write it into the .in file. **explanation is given inside two... (9 Replies)
Discussion started by: liuzhencc
9 Replies

2. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

3. Shell Programming and Scripting

Need to add code to hundreds of .html files

Need assistance to add code to hundreds of .html Code will look like below and needs to be added below <html> tag: <script> Some .js code here </script> This will be used in Fedora release 7 (Moonshine). I will appreciate any type of help and/or orientation. Thank you! (4 Replies)
Discussion started by: Ferocci
4 Replies

4. Shell Programming and Scripting

Best way to connect to hundreds of nodes and grep log files

Hi, What will be the best way to connect (ssh) to hundreds of nodes and grep log files parallely from shell. Using for loop seems to be sequential. Are there any shell built in construct which could be used to achieve this? Is the sub shell any good here? (1 Reply)
Discussion started by: agent001
1 Replies

5. Shell Programming and Scripting

Renaming folders all at a time

I have a set of folders like Jan1st, Jan2nd, Jan3rd... and so on. I need to rename them to Jan1st2010,Jan2nd2010 .... and so on at one shot. (4 Replies)
Discussion started by: realspirituals
4 Replies

6. UNIX for Dummies Questions & Answers

adding hundreds of numbers

i know how to add two numbers using expr, but if i have a file with hundreds of numbers, how do i add them all together, without typing them all one by one? for example, file.txt contains 4 5 6 7 how can i give a command to add them, without typing $ expr `4 + 5 + 6 + 7` (7 Replies)
Discussion started by: FOBoy
7 Replies

7. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

8. Shell Programming and Scripting

for loops can i loop in hundreds?

I have the following for ((i=100; i<=1000; i++)) do this goes in increments of 1 I need it to go up in increments of 100, how is that done in a for loop? (1 Reply)
Discussion started by: gazz1982
1 Replies

9. UNIX for Dummies Questions & Answers

Renaming files to have date/time in filename

I have a program that will export my data to a single file, but it assigns a file name that is overridden every time I run the program. I need to change the file name to have a sequential number in the filename. How do I rename a file so that the filename contains the system date and time. I want... (5 Replies)
Discussion started by: wayneb
5 Replies
Login or Register to Ask a Question