Copying & moving en masse


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copying & moving en masse
# 1  
Old 05-29-2008
Question Copying & moving en masse

I'm new to UNIX and have got some of the basics down, but I've got a puzzle I'm having difficulty working out. Smilie

Scenario:

Have FILE_A.JPG in DIR_A

Need to copy FILE_A 200 times and rename it 200 different names. List of 200 names in NAME_FILE.TXT

After renaming 200 files, need to move each file into a specific directory based on file name.

EXAMPLE:

FILE is in CURRENT_DIR needs to move to DESTINATION_DIR

234546 is in DIR_A needs to move to DIR_B/6/46
498721 is in DIR_A needs to move to DIR_B/1/21
873489 is in DIR_A needs to move to DIR_B/9/89
459323 is in DIR_A needs to move to DIR_B/3/23

PUZZLE: How to copy & rename the 200 files and then move each file into the new destination directory?

Any recommendations for me?
# 2  
Old 05-29-2008
I'm having trouble understanding exactly what you want... but I'll give it a shot...

cd DIR_A
for i in `cat NAME_FILE.TXT`; do dir=DIR_B/`echo $i|cut -c6`/`echo $i|cut -c5,6`; mkdir -p ../$dir; cp FILE_A.JPG ../$dir/$i;done

I have made the following assumptions:
- every file name in NAME_FILE.TXT has 6 characters
- the directory you want to create is the last charater / last 2 characters

let me know if those assumptions aren't correct...

Last edited by jimcanoa; 05-29-2008 at 11:00 PM..
# 3  
Old 05-30-2008
Quote:
Originally Posted by jimcanoa

I have made the following assumptions:
- every file name in NAME_FILE.TXT has 6 characters
- the directory you want to create is the last charater / last 2 characters

let me know if those assumptions aren't correct...
Thank you for the attempt, and sorry if I wasn't very clear.

-The file names in NAME_FILE.TXT vary in character size from 4-10 characters.
-The destination directories already exist as you assumed 'character / last 2 characters'
# 4  
Old 05-31-2008
How about this, then:
Code:
for i in `cat NAME_FILE.TXT`; do size=$((`echo $i|wc -m`-1));dir=$(echo $i|cut -c$size)/$(echo $i|cut -c$(($size-1)),$size ); cp FILE_A.JPG DIR_B/$dir/$i;done

Although one liners are cool, I would do this with perl, it's just clearer Smilie
# 5  
Old 06-02-2008
Thank you for the advice. I will give this a try. Perl...just something else I need to study. Thanks again!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with copying from one drive to another with cgi & ksh script

Hi I was hoping some one could help me with a problem I have with a .cgi script I am running in the korn shell. I have created a web form that user fill out to gather information that I use a .cgi and sed script to translate into a xml file which is further processed by another program. All is... (6 Replies)
Discussion started by: Paul Walker
6 Replies

2. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

3. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

4. Shell Programming and Scripting

Copying the Header & footer Information to the Outfile.

Hi I am writing a perl script which checks for the specific column values from a file and writes to the OUT file. So the feed file has a header information and footer information. I header information isaround107 lines i.e. Starts with START-OF-FILE ....... so on .... ... (11 Replies)
Discussion started by: filter
11 Replies

5. Shell Programming and Scripting

copying file information using awk & grep

Hi, TASK 1: I have been using this code to print the information of files kept at "/castor/cern.ch/user/s/sudha/forPooja" in some text file name FILE.txt. rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > FILE.txt ... (6 Replies)
Discussion started by: nrjrasaxena
6 Replies

6. Shell Programming and Scripting

Help needed in perl; moving or copying the variables

Hi All, I have a perl script blc.pl; i have five variables a,b,c,d and e in this script. Now I want to copy the values of these variables into a data file,say abc.dat.. Can anybody please tell me how to do this? Any help is appreciated.. Thanks in advance (2 Replies)
Discussion started by: puneetkanchi
2 Replies

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

8. Shell Programming and Scripting

Finding & Copying files

Hello :) can someone please help me with this task: I am in the shell, in folder "Main" below the folder Main are sub folders: "sourceA", "Source B", and "target" in sourceA and source B are files, and in folder "Main" is a textfile, with filenames, one filename per line. I need a... (4 Replies)
Discussion started by: Y-T
4 Replies

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

10. 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
Login or Register to Ask a Question