Moving files out of multiple directories and renaming them in numerical order


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Moving files out of multiple directories and renaming them in numerical order
# 1  
Old 01-13-2010
Moving files out of multiple directories and renaming them in numerical order

Hi,
I have 500 directories each with multiple data files inside them. The names are sort of random. For example, one directory has files named e_1.dat, e_5.dat, e_8.dat, etc. I need to move the files to a single directory and rename them all in numerical order, from 1.dat to 1000(or some number).dat. Does anyone know how this could be done? I'm most comfortable with Perl, but any other way of doing it would be perfectly fine.
Thanks!
# 2  
Old 01-13-2010
Hi my friend, try this:

Code:
#!/usr/bin/bash
for j in $(find . -type f -name "*.dat" | wc -l)
do
find . -type f -name "*.dat" >> all_files.txt
while read line;
        do
        mv $line /YOUR_PATH/my_file$j.dat
done<all_files.txt
done

regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming files in multiple directories

Hi I have the following file structure and I want to rename all the abc.jar files to abc_backup.jar rock@server:~/rakesh> ls -R .: test1 test2 test3 ./test1: abc.jar ./test2: abc.jar ./test3: abc.jar (2 Replies)
Discussion started by: rakeshkumar
2 Replies

2. Shell Programming and Scripting

Moving and renaming multiple files in a directory

Hi. I am trying to automate the movement and renaming of a number of files in a directory. I am using the 'mv' command as I do not have access to 'rename'. I have the following scripted FILES=$(ls /transfer/move/sys/mail/20130123/) if ; then for i in ${FILES} ; do mv... (4 Replies)
Discussion started by: jimbojames
4 Replies

3. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

4. UNIX for Dummies Questions & Answers

finding and moving files based on the last three numerical characters in the filename

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190, all in one directory. Now the last three numeric characters, in this case 999, can be anything from 001 to 999. I need to move some of them to a seperate directory, the ones I need to... (5 Replies)
Discussion started by: roche.j.mike
5 Replies

5. UNIX for Dummies Questions & Answers

moving/copying files in a numerical order

Hi I am newbie to unix scripting, but i have enough knowledge to understand. I have a specific questions like, I use to collect like 3500 files per experiment, each one named like data_001.img.. data_002.img data_003.img .... data_3500.img I would like to move every 12 files in the 3500... (3 Replies)
Discussion started by: wpat
3 Replies

6. UNIX for Dummies Questions & Answers

Renaming files after their directory name in multiple sub directories

So I am not sure if this should go in the shell forum or in the beginners. It is my first time posting on these forums. I have a directory, main_dir lets say, with multiple sub directories (one_dir through onehundred_dir for example) and in each sub directory there is a test.txt. How would one... (2 Replies)
Discussion started by: robotsbite
2 Replies

7. Shell Programming and Scripting

Moving multiple files and renaming them on the fly

Hi All, Being new to scripting I am facing a new situation. We have an application that generates a file lets say dumpfile for each user under the users home directory when they execute the application. This is quite a huge file and imagine having that for over 40 users on a daily basis. The... (1 Reply)
Discussion started by: daemongk
1 Replies

8. Shell Programming and Scripting

moving and renaming multiple files

Greetings, I know i can use the mv command to move and rename one file. How can I do this with multiple files? example pic01.bmp to pic0001.bmp how can i perform this function on an entire directory of sequential files and keep them in sequence? Hints, suggestions are most welcome:) ... (1 Reply)
Discussion started by: rocinante
1 Replies

9. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies

10. Shell Programming and Scripting

Listing files in numerical order

Hi, I'm trying to write a ksh script to copy a specified number of files from one directory to another. The files are named in the convention <switchname>_log.<num> and the numbers are sequential single digit onwards. I figured I could find some parameter for ls which would list the files in... (3 Replies)
Discussion started by: Steve_H
3 Replies
Login or Register to Ask a Question