How can I copy a specific line to a specific folder? - Debian/Bash/Linux
I am trying to copy a specific line which is in a file, into a specific folder name.
And this folder must have the equal name than this line.
Let me explain :
I have 3 folders :
- /home/my_username/bin : which contains inside of it a file, which is my script file : switch_menu
- /home/student : which contains inside of it, my 2 students files : Rick and Josh
And inside of each of both files, there are all the subjects names followed by the respectives score they received for it. - /home/result : which contain inside of it, my 2 subjects lessons files : MATH and HISTORY
And inside of each of both files, there are the students name followed by the score they received for this specific lesson subject.
Here are my codes for a better understanding :
1. My script file | Inside of /home/my_username/bin
#! /bin/bash
title="Switch Menu"
prompt="Please pick an option :"
echo "$title"
PS3="$prompt"
select opt in "${options[@]}"
do
case $REPLY in
1) cat /home/result/MATH >>/home/student/Rick;;
2) echo "Goodbye !"; break;;
3) echo "The option $REPLY does not exit !";;
esac
done
2. My student files | Inside of /home/student
-rw-r--r-- 1 username username 0 month date time Rick
-rw-r--r-- 1 username username 0 month date time Josh
3. My result files | Inside of /home/result
-rw-r--r-- 1 username username 0 month date time MATH
-rw-r--r-- 1 username username 0 month date time HISTORY
cat MATH | Gives me
Rick 7
Josh 14
cat HISTORY| Gives me
Rick 18
Josh 11
Right now, if I run my script : switch_menu,
And type the choice 1, it will simply copy all the content of my MATH file, inside my RICK file.
Though in my MATH file, there is also the score for Josh
It shouldn't be like it.
It should be this : once I click on "1", it copies the score for each of my respectives students.
So that for this example, it should copy :
Rick 7, inside of the Rick file.
Josh 14, inside of the Josh file.
How can I make it this way please?
linux bash debian
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I am trying to copy a specific line which is in a file, into a specific folder name.
And this folder must have the equal name than this line.
Let me explain :
I have 3 folders :
- /home/my_username/bin : which contains inside of it a file, which is my script file : switch_menu
- /home/student : which contains inside of it, my 2 students files : Rick and Josh
And inside of each of both files, there are all the subjects names followed by the respectives score they received for it. - /home/result : which contain inside of it, my 2 subjects lessons files : MATH and HISTORY
And inside of each of both files, there are the students name followed by the score they received for this specific lesson subject.
Here are my codes for a better understanding :
1. My script file | Inside of /home/my_username/bin
#! /bin/bash
title="Switch Menu"
prompt="Please pick an option :"
echo "$title"
PS3="$prompt"
select opt in "${options[@]}"
do
case $REPLY in
1) cat /home/result/MATH >>/home/student/Rick;;
2) echo "Goodbye !"; break;;
3) echo "The option $REPLY does not exit !";;
esac
done
2. My student files | Inside of /home/student
-rw-r--r-- 1 username username 0 month date time Rick
-rw-r--r-- 1 username username 0 month date time Josh
3. My result files | Inside of /home/result
-rw-r--r-- 1 username username 0 month date time MATH
-rw-r--r-- 1 username username 0 month date time HISTORY
cat MATH | Gives me
Rick 7
Josh 14
cat HISTORY| Gives me
Rick 18
Josh 11
Right now, if I run my script : switch_menu,
And type the choice 1, it will simply copy all the content of my MATH file, inside my RICK file.
Though in my MATH file, there is also the score for Josh
It shouldn't be like it.
It should be this : once I click on "1", it copies the score for each of my respectives students.
So that for this example, it should copy :
Rick 7, inside of the Rick file.
Josh 14, inside of the Josh file.
How can I make it this way please?
linux bash debian
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I am trying to copy a specific line which is in a file, into a specific folder name.
And this folder must have the equal name than this line.
Let me explain :
I have 3 folders :
- /home/my_username/bin : which contains inside of it a file, which is my script file : switch_menu
- /home/student : which contains inside of it, my 2 students files : Rick and Josh
And inside of each of both files, there are all the subjects names followed by the respectives score they received for it. - /home/result : which contain inside of it, my 2 subjects lessons files : MATH and HISTORY
And inside of each of both files, there are the students name followed by the score they received for this specific lesson subject.
Here are my codes for a better understanding :
1. My script file | Inside of /home/my_username/bin
#! /bin/bash
title="Switch Menu"
prompt="Please pick an option :"
echo "$title"
PS3="$prompt"
select opt in "${options[@]}"
do
case $REPLY in
1) cat /home/result/MATH >>/home/student/Rick;;
2) echo "Goodbye !"; break;;
3) echo "The option $REPLY does not exit !";;
esac
done
2. My student files | Inside of /home/student
-rw-r--r-- 1 username username 0 month date time Rick
-rw-r--r-- 1 username username 0 month date time Josh
3. My result files | Inside of /home/result
-rw-r--r-- 1 username username 0 month date time MATH
-rw-r--r-- 1 username username 0 month date time HISTORY
cat MATH | Gives me
Rick 7
Josh 14
cat HISTORY| Gives me
Rick 18
Josh 11
Right now, if I run my script : switch_menu,
And type the choice 1, it will simply copy all the content of my MATH file, inside my RICK file.
Though in my MATH file, there is also the score for Josh
It shouldn't be like it.
It should be this : once I click on "1", it copies the score for each of my respectives students.
So that for this example, it should copy :
Rick 7, inside of the Rick file.
Josh 14, inside of the Josh file.
How can I make it this way please?
linux bash debian
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am trying to copy a specific line which is in a file, into a specific folder name.
And this folder must have the equal name than this line.
Let me explain :
I have 3 folders :
- /home/my_username/bin : which contains inside of it a file, which is my script file : switch_menu
- /home/student : which contains inside of it, my 2 students files : Rick and Josh
And inside of each of both files, there are all the subjects names followed by the respectives score they received for it. - /home/result : which contain inside of it, my 2 subjects lessons files : MATH and HISTORY
And inside of each of both files, there are the students name followed by the score they received for this specific lesson subject.
Here are my codes for a better understanding :
1. My script file | Inside of /home/my_username/bin
#! /bin/bash
title="Switch Menu"
prompt="Please pick an option :"
echo "$title"
PS3="$prompt"
select opt in "${options[@]}"
do
case $REPLY in
1) cat /home/result/MATH >>/home/student/Rick;;
2) echo "Goodbye !"; break;;
3) echo "The option $REPLY does not exit !";;
esac
done
2. My student files | Inside of /home/student
-rw-r--r-- 1 username username 0 month date time Rick
-rw-r--r-- 1 username username 0 month date time Josh
3. My result files | Inside of /home/result
-rw-r--r-- 1 username username 0 month date time MATH
-rw-r--r-- 1 username username 0 month date time HISTORY
cat MATH | Gives me
Rick 7
Josh 14
cat HISTORY| Gives me
Rick 18
Josh 11
Right now, if I run my script : switch_menu,
And type the choice 1, it will simply copy all the content of my MATH file, inside my RICK file.
Though in my MATH file, there is also the score for Josh
It shouldn't be like it.
It should be this : once I click on "1", it copies the score for each of my respectives students.
So that for this example, it should copy :
Rick 7, inside of the Rick file.
Josh 14, inside of the Josh file.
How can I make it this way please?
linux bash debian
linux bash debian
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 1 hour ago
user333607user333607
61
61
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user333607 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If I understand you correctly, you need to add the grades from a result file (e.g. math.txt) to the corresponding students file (e.g. rick.txt, josh.txt).
The way, that you are doing it right now
cat /home/result/MATH >>/home/student/Rick;;
is incomplete. You need to find a way to filter and process the information in the lines read from the math file.
I don't want to give you a complete solution, because it sounds like homework to me. But I will give you an examples:
sh$ cat math.txt
Mike 12
Romeo 8
Peter 13
Following command
sh$ grep "Mike" math.txt
Mike 12
would only return the one line.
Further you can split the lines into single columns.
sh$ grep "Mike" math.txt | cut -d' ' -f2
12
would only return the 2nd column with the grade.
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
});
}
});
user333607 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f496950%2fhow-can-i-copy-a-specific-line-to-a-specific-folder-debian-bash-linux%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
If I understand you correctly, you need to add the grades from a result file (e.g. math.txt) to the corresponding students file (e.g. rick.txt, josh.txt).
The way, that you are doing it right now
cat /home/result/MATH >>/home/student/Rick;;
is incomplete. You need to find a way to filter and process the information in the lines read from the math file.
I don't want to give you a complete solution, because it sounds like homework to me. But I will give you an examples:
sh$ cat math.txt
Mike 12
Romeo 8
Peter 13
Following command
sh$ grep "Mike" math.txt
Mike 12
would only return the one line.
Further you can split the lines into single columns.
sh$ grep "Mike" math.txt | cut -d' ' -f2
12
would only return the 2nd column with the grade.
add a comment |
If I understand you correctly, you need to add the grades from a result file (e.g. math.txt) to the corresponding students file (e.g. rick.txt, josh.txt).
The way, that you are doing it right now
cat /home/result/MATH >>/home/student/Rick;;
is incomplete. You need to find a way to filter and process the information in the lines read from the math file.
I don't want to give you a complete solution, because it sounds like homework to me. But I will give you an examples:
sh$ cat math.txt
Mike 12
Romeo 8
Peter 13
Following command
sh$ grep "Mike" math.txt
Mike 12
would only return the one line.
Further you can split the lines into single columns.
sh$ grep "Mike" math.txt | cut -d' ' -f2
12
would only return the 2nd column with the grade.
add a comment |
If I understand you correctly, you need to add the grades from a result file (e.g. math.txt) to the corresponding students file (e.g. rick.txt, josh.txt).
The way, that you are doing it right now
cat /home/result/MATH >>/home/student/Rick;;
is incomplete. You need to find a way to filter and process the information in the lines read from the math file.
I don't want to give you a complete solution, because it sounds like homework to me. But I will give you an examples:
sh$ cat math.txt
Mike 12
Romeo 8
Peter 13
Following command
sh$ grep "Mike" math.txt
Mike 12
would only return the one line.
Further you can split the lines into single columns.
sh$ grep "Mike" math.txt | cut -d' ' -f2
12
would only return the 2nd column with the grade.
If I understand you correctly, you need to add the grades from a result file (e.g. math.txt) to the corresponding students file (e.g. rick.txt, josh.txt).
The way, that you are doing it right now
cat /home/result/MATH >>/home/student/Rick;;
is incomplete. You need to find a way to filter and process the information in the lines read from the math file.
I don't want to give you a complete solution, because it sounds like homework to me. But I will give you an examples:
sh$ cat math.txt
Mike 12
Romeo 8
Peter 13
Following command
sh$ grep "Mike" math.txt
Mike 12
would only return the one line.
Further you can split the lines into single columns.
sh$ grep "Mike" math.txt | cut -d' ' -f2
12
would only return the 2nd column with the grade.
answered 50 mins ago
oxdecaoxdeca
112
112
add a comment |
add a comment |
user333607 is a new contributor. Be nice, and check out our Code of Conduct.
user333607 is a new contributor. Be nice, and check out our Code of Conduct.
user333607 is a new contributor. Be nice, and check out our Code of Conduct.
user333607 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f496950%2fhow-can-i-copy-a-specific-line-to-a-specific-folder-debian-bash-linux%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