2

I'm trying to copy directories of data sets that pertain to the a certain case but the data sets are currently stored in different directories and with different (non consecutive) numbered file.

e.g. I have a case file case_directory/006 and I want to copy and create case_directory/006/MRS from where that case's MRS directory is currently stored in data_directory/150/MRS. The next case would be case_directory/010 and for that I would want to copy data_directory/155/MRS - just to illustrate there is really no relation between the numbering systems. I have about 120 of such case directories so would be great to automate the copying process from the matching data directory! :-/

Can I automate this using the for and cat commands and text files containing lists where the matching numbers are on the same row in each text file? can you use more than 1 variable with for or do I need to use a more complicated script?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • 1
    Use a while/read loop: while read num1 num2; do cp -R case_directory/$num1/MRS data_directory/$num2; done < file_with_matching_nums instead of a for loop. – muru Sep 09 '15 at 21:23

1 Answers1

2

Assuming your data file looks like this

006 150
010 155
...

You can use a simple loop to read the source and destination numbers

while read ncase ndata
do
    cp -a case_directory/$ncase/MRS data_directory/$ndata/
done < casedatafile
Chris Davies
  • 116,213
  • 16
  • 160
  • 287