Copying directories unrelated file names
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
add a comment |
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
1
Use awhile/readloop:while read num1 num2; do cp -R case_directory/$num1/MRS data_directory/$num2; done < file_with_matching_numsinstead of aforloop.
– muru
Sep 9 '15 at 21:23
add a comment |
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
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
bash cp for
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 awhile/readloop:while read num1 num2; do cp -R case_directory/$num1/MRS data_directory/$num2; done < file_with_matching_numsinstead of aforloop.
– muru
Sep 9 '15 at 21:23
add a comment |
1
Use awhile/readloop:while read num1 num2; do cp -R case_directory/$num1/MRS data_directory/$num2; done < file_with_matching_numsinstead of aforloop.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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
thank you so much @muru and @roaima - worked a treat! Will be usingwhile readuntil I'm blue in the face now!
– Justin
Sep 10 '15 at 12:07
There are many reasons not to usewhile readwithout serious pause for thought. Here, though, it's a sufficient solution.
– roaima
Sep 10 '15 at 12:15
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
thank you so much @muru and @roaima - worked a treat! Will be usingwhile readuntil I'm blue in the face now!
– Justin
Sep 10 '15 at 12:07
There are many reasons not to usewhile readwithout serious pause for thought. Here, though, it's a sufficient solution.
– roaima
Sep 10 '15 at 12:15
add a comment |
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
thank you so much @muru and @roaima - worked a treat! Will be usingwhile readuntil I'm blue in the face now!
– Justin
Sep 10 '15 at 12:07
There are many reasons not to usewhile readwithout serious pause for thought. Here, though, it's a sufficient solution.
– roaima
Sep 10 '15 at 12:15
add a comment |
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
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
answered Sep 9 '15 at 21:25
roaimaroaima
44.5k555119
44.5k555119
thank you so much @muru and @roaima - worked a treat! Will be usingwhile readuntil I'm blue in the face now!
– Justin
Sep 10 '15 at 12:07
There are many reasons not to usewhile readwithout serious pause for thought. Here, though, it's a sufficient solution.
– roaima
Sep 10 '15 at 12:15
add a comment |
thank you so much @muru and @roaima - worked a treat! Will be usingwhile readuntil I'm blue in the face now!
– Justin
Sep 10 '15 at 12:07
There are many reasons not to usewhile readwithout 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Use a
while/readloop:while read num1 num2; do cp -R case_directory/$num1/MRS data_directory/$num2; done < file_with_matching_numsinstead of aforloop.– muru
Sep 9 '15 at 21:23