Copying directories unrelated file names












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?










share|improve this question




















  • 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 9 '15 at 21:23


















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?










share|improve this question




















  • 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 9 '15 at 21:23
















2












2








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?










share|improve this question
















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?







bash cp for






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 26 at 23:57









Rui F Ribeiro

39.9k1479134




39.9k1479134










asked Sep 9 '15 at 21:12









Justin Justin

111




111








  • 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 9 '15 at 21:23
















  • 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 9 '15 at 21:23










1




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 9 '15 at 21:23







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 9 '15 at 21:23












1 Answer
1






active

oldest

votes


















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





share|improve this answer
























  • thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

    – Justin
    Sep 10 '15 at 12:07











  • There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

    – roaima
    Sep 10 '15 at 12:15













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f228661%2fcopying-directories-unrelated-file-names%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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





share|improve this answer
























  • thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

    – Justin
    Sep 10 '15 at 12:07











  • There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

    – roaima
    Sep 10 '15 at 12:15


















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





share|improve this answer
























  • thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

    – Justin
    Sep 10 '15 at 12:07











  • There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

    – roaima
    Sep 10 '15 at 12:15
















2












2








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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 9 '15 at 21:25









roaimaroaima

44.5k555119




44.5k555119













  • thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

    – Justin
    Sep 10 '15 at 12:07











  • There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

    – roaima
    Sep 10 '15 at 12:15





















  • thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

    – Justin
    Sep 10 '15 at 12:07











  • There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

    – roaima
    Sep 10 '15 at 12:15



















thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

– Justin
Sep 10 '15 at 12:07





thank you so much @muru and @roaima - worked a treat! Will be using while read until I'm blue in the face now!

– Justin
Sep 10 '15 at 12:07













There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

– roaima
Sep 10 '15 at 12:15







There are many reasons not to use while read without serious pause for thought. Here, though, it's a sufficient solution.

– roaima
Sep 10 '15 at 12:15




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f228661%2fcopying-directories-unrelated-file-names%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book