moving/copying files in a numerical order


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers moving/copying files in a numerical order
# 1  
Old 12-11-2010
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 files like, data_001 to data_012.img to a separate directory and data_013.img to data_024.img...and so on. to another directories. I am wondering how to do that by scripting, without doing it manually.
I tried lmoving files using this command, but it does not work

cp data_*([001-012])*

Could you please someone provide me way to do this? thanks in advance.
# 2  
Old 12-11-2010
Please show a detailed example which includes the name structure of the subdirectories and makes the rules totally clear.

Does every file between 001 and 3500 exist?
# 3  
Old 12-13-2010
Hi
I have a folder named study1 under /home/pat/data/study1, which contains all 3500 files with .img extension, and numerically arranged from 001 to 3500. My interest is to move 12 files (from data_ 001 to 012.img) to previous folder (/home/pat/set1) with some name like set1
and next data_013 to 024.img to set2 like this.
thsi is what i mean
Thanks
Pat
# 4  
Old 12-13-2010
Checks existance of files and only tries to move files that exist. Will only create set directory if 1 or more filse exists for range of the 12 value range:

Code:
#/bin/ksh
cd /home/pat/data/study1
num=0
while [ $num -le 3500 ]
do
    FILE=$(printf "data_%03d.img" $num)
    [ -f $FILE ] && MVLIST="$MVLIST $FILE"
    if [ $(($num % 12)) -eq 0 ] || [ $num -eq 3500 ]
    then
        if [ -n "$MVLIST" ]
        then
            [ -d $dir ] || mkdir $dir
            mv $MVLIST $dir
        fi
        MVLIST=
        dir=/home/pat/data/set$((1+num/12))
    fi
    let num+=1
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

How to sort a column based on numerical ascending order if it includes e-10?

I have a column of numbers in the following format: 1.722e-05 2.018e-05 2.548e-05 2.747e-05 7.897e-05 4.016e-05 4.613e-05 4.613e-05 5.151e-05 5.151e-05 5.151e-05 6.1e-05 6.254e-05 7.04e-05 7.12e-05 7.12e-05 (6 Replies)
Discussion started by: evelibertine
6 Replies

3. 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

4. Programming

Sorting a vector of strings into numerical order.

I have a vector of strings that contain a list of channels like this: 101,99,22HD,432,300HD I have tried using the sort routine like this: sort(mychans.begin(),mychans.end()); For some reason my channels are not being sorted at all. I was hoping someone might have some input that might... (2 Replies)
Discussion started by: sepoto
2 Replies

5. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: renthead720
1 Replies

6. Shell Programming and Scripting

FTP files are not moving/copying

Hi I want to FTP some file from one server to another server, those file should copy from one server to another and then move the same files to another folder in the same server. I have written the code but the text files are moving and coping but the remaing file are not moving or coping to... (4 Replies)
Discussion started by: mahantysk
4 Replies

7. Shell Programming and Scripting

Sorting Files by date and moving files in date order

I need to build a k shell script that will sort files in a directory where files appear like this "XXXX_2008021213.DAT. I need to sort by date in the filename and then move files by individual date to a working folder. concatenate the files in the working folder then start a process once... (2 Replies)
Discussion started by: rebel64
2 Replies

8. Solaris

copying/moving partition

I have a slice on a 72GB hard drive like this (example): /dev/dsk/c0t1d0s0 51424287 51009 50859036 1% /usr/stuff that I need to copy or move to a slice on a MUCH larger slice like this: /dev/dsk/c0t2d0s6 70592505 570236 69316344 1% /usr/newstuff What is the... (4 Replies)
Discussion started by: antalexi
4 Replies

9. Shell Programming and Scripting

Copying Files in the same order along with time stamps

Hi , I am New to this group and would like to know if someone can help me on this issue : We need to copy some files from a particular directory to another directory in the same order and time stamps .How can this be achieved . For Ex : ./ABC/disk101/XYZ has 1000 files with varying... (2 Replies)
Discussion started by: shyam.appalla
2 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