strategies, for a beginner, to write code (to answer homework question) [duplicate]
up vote
0
down vote
favorite
This question is an exact duplicate of:
Replace string in one file with contents of another file when match column
1 answer
There will be a file called replacewords.txt
This will contain data like
Apple Orange
Banana Guava
etc.
There will be another file called data.txt
. Word in this file will be replaces, such that, the first column words (from replacewords.txt
) should be replaced by second column words.
For example if we find Apple
(in data.txt
), then replace it by Orange
and Banana
by Guava
etc.
The result should be stored in Results.txt
shell-script
New contributor
marked as duplicate by Kusalananda
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 10:43
This question was marked as an exact duplicate of an existing question.
add a comment |
up vote
0
down vote
favorite
This question is an exact duplicate of:
Replace string in one file with contents of another file when match column
1 answer
There will be a file called replacewords.txt
This will contain data like
Apple Orange
Banana Guava
etc.
There will be another file called data.txt
. Word in this file will be replaces, such that, the first column words (from replacewords.txt
) should be replaced by second column words.
For example if we find Apple
(in data.txt
), then replace it by Orange
and Banana
by Guava
etc.
The result should be stored in Results.txt
shell-script
New contributor
marked as duplicate by Kusalananda
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 10:43
This question was marked as an exact duplicate of an existing question.
2
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question is an exact duplicate of:
Replace string in one file with contents of another file when match column
1 answer
There will be a file called replacewords.txt
This will contain data like
Apple Orange
Banana Guava
etc.
There will be another file called data.txt
. Word in this file will be replaces, such that, the first column words (from replacewords.txt
) should be replaced by second column words.
For example if we find Apple
(in data.txt
), then replace it by Orange
and Banana
by Guava
etc.
The result should be stored in Results.txt
shell-script
New contributor
This question is an exact duplicate of:
Replace string in one file with contents of another file when match column
1 answer
There will be a file called replacewords.txt
This will contain data like
Apple Orange
Banana Guava
etc.
There will be another file called data.txt
. Word in this file will be replaces, such that, the first column words (from replacewords.txt
) should be replaced by second column words.
For example if we find Apple
(in data.txt
), then replace it by Orange
and Banana
by Guava
etc.
The result should be stored in Results.txt
This question is an exact duplicate of:
Replace string in one file with contents of another file when match column
1 answer
shell-script
shell-script
New contributor
New contributor
edited Nov 23 at 10:29
ctrl-alt-delor
10.2k41955
10.2k41955
New contributor
asked Nov 23 at 10:09
data analyst
1
1
New contributor
New contributor
marked as duplicate by Kusalananda
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 10:43
This question was marked as an exact duplicate of an existing question.
marked as duplicate by Kusalananda
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 10:43
This question was marked as an exact duplicate of an existing question.
2
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57
add a comment |
2
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57
2
2
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
[I will assume that you are using bash and Gnu utils.]
First break up the question, and tackle one bit at a time.
Before starting ask “what tools have I been learning?”
Breaking it up
For this example I would break it up like this. (you only need to identify the first one. Get it working, then identify the 2nd. However I have identified some more to help you.)
After each step, test it. Does it work, if not fix it. If it works, then move to next step.
- Read a file (
data.txt
) [cat] - Read a file and copy/output it to another file (
Result.txt
) [cat and redirection] - Do a replacement. Don't worry about
replacewords.txt
. Can you just replace Apple with Orange. [sed, and redirection] - Read in
replacewords.txt
, and use this to control the replacements.
I have to have a think about what tool can do this. It seems to be a two step process. What option do I have?
- Write a script that reads
replacewords.txt
, generates ased
script, and then executes it. (If I go this way, then first practice by writing ased
script that will replace Apples with Oranges and Banana with Guava.) - Do it in awk (still a two stage process. Use BEGIN clause to do setup stage.).
- Do it in python (still a two stage process).
- Note: Write a dummy stage 1. Hard coding one and then two substitutions. Get it to work, before getting stage 1 to read
replacewords.txt
.
- Write a script that reads
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
[I will assume that you are using bash and Gnu utils.]
First break up the question, and tackle one bit at a time.
Before starting ask “what tools have I been learning?”
Breaking it up
For this example I would break it up like this. (you only need to identify the first one. Get it working, then identify the 2nd. However I have identified some more to help you.)
After each step, test it. Does it work, if not fix it. If it works, then move to next step.
- Read a file (
data.txt
) [cat] - Read a file and copy/output it to another file (
Result.txt
) [cat and redirection] - Do a replacement. Don't worry about
replacewords.txt
. Can you just replace Apple with Orange. [sed, and redirection] - Read in
replacewords.txt
, and use this to control the replacements.
I have to have a think about what tool can do this. It seems to be a two step process. What option do I have?
- Write a script that reads
replacewords.txt
, generates ased
script, and then executes it. (If I go this way, then first practice by writing ased
script that will replace Apples with Oranges and Banana with Guava.) - Do it in awk (still a two stage process. Use BEGIN clause to do setup stage.).
- Do it in python (still a two stage process).
- Note: Write a dummy stage 1. Hard coding one and then two substitutions. Get it to work, before getting stage 1 to read
replacewords.txt
.
- Write a script that reads
add a comment |
up vote
0
down vote
[I will assume that you are using bash and Gnu utils.]
First break up the question, and tackle one bit at a time.
Before starting ask “what tools have I been learning?”
Breaking it up
For this example I would break it up like this. (you only need to identify the first one. Get it working, then identify the 2nd. However I have identified some more to help you.)
After each step, test it. Does it work, if not fix it. If it works, then move to next step.
- Read a file (
data.txt
) [cat] - Read a file and copy/output it to another file (
Result.txt
) [cat and redirection] - Do a replacement. Don't worry about
replacewords.txt
. Can you just replace Apple with Orange. [sed, and redirection] - Read in
replacewords.txt
, and use this to control the replacements.
I have to have a think about what tool can do this. It seems to be a two step process. What option do I have?
- Write a script that reads
replacewords.txt
, generates ased
script, and then executes it. (If I go this way, then first practice by writing ased
script that will replace Apples with Oranges and Banana with Guava.) - Do it in awk (still a two stage process. Use BEGIN clause to do setup stage.).
- Do it in python (still a two stage process).
- Note: Write a dummy stage 1. Hard coding one and then two substitutions. Get it to work, before getting stage 1 to read
replacewords.txt
.
- Write a script that reads
add a comment |
up vote
0
down vote
up vote
0
down vote
[I will assume that you are using bash and Gnu utils.]
First break up the question, and tackle one bit at a time.
Before starting ask “what tools have I been learning?”
Breaking it up
For this example I would break it up like this. (you only need to identify the first one. Get it working, then identify the 2nd. However I have identified some more to help you.)
After each step, test it. Does it work, if not fix it. If it works, then move to next step.
- Read a file (
data.txt
) [cat] - Read a file and copy/output it to another file (
Result.txt
) [cat and redirection] - Do a replacement. Don't worry about
replacewords.txt
. Can you just replace Apple with Orange. [sed, and redirection] - Read in
replacewords.txt
, and use this to control the replacements.
I have to have a think about what tool can do this. It seems to be a two step process. What option do I have?
- Write a script that reads
replacewords.txt
, generates ased
script, and then executes it. (If I go this way, then first practice by writing ased
script that will replace Apples with Oranges and Banana with Guava.) - Do it in awk (still a two stage process. Use BEGIN clause to do setup stage.).
- Do it in python (still a two stage process).
- Note: Write a dummy stage 1. Hard coding one and then two substitutions. Get it to work, before getting stage 1 to read
replacewords.txt
.
- Write a script that reads
[I will assume that you are using bash and Gnu utils.]
First break up the question, and tackle one bit at a time.
Before starting ask “what tools have I been learning?”
Breaking it up
For this example I would break it up like this. (you only need to identify the first one. Get it working, then identify the 2nd. However I have identified some more to help you.)
After each step, test it. Does it work, if not fix it. If it works, then move to next step.
- Read a file (
data.txt
) [cat] - Read a file and copy/output it to another file (
Result.txt
) [cat and redirection] - Do a replacement. Don't worry about
replacewords.txt
. Can you just replace Apple with Orange. [sed, and redirection] - Read in
replacewords.txt
, and use this to control the replacements.
I have to have a think about what tool can do this. It seems to be a two step process. What option do I have?
- Write a script that reads
replacewords.txt
, generates ased
script, and then executes it. (If I go this way, then first practice by writing ased
script that will replace Apples with Oranges and Banana with Guava.) - Do it in awk (still a two stage process. Use BEGIN clause to do setup stage.).
- Do it in python (still a two stage process).
- Note: Write a dummy stage 1. Hard coding one and then two substitutions. Get it to work, before getting stage 1 to read
replacewords.txt
.
- Write a script that reads
edited Nov 23 at 10:50
answered Nov 23 at 10:40
ctrl-alt-delor
10.2k41955
10.2k41955
add a comment |
add a comment |
2
This is not a do my homework site. However I will give you some help, but not the answer.
– ctrl-alt-delor
Nov 23 at 10:15
Are you constrained to using a particular language? Which one? What have you tried so far? Do you have any ideas?
– ctrl-alt-delor
Nov 23 at 10:16
This question may be better served on cseducators.stackexchange.com (if you like the changes I have made). If so, tell me, and I will ask for it to be moved. The other site is only for asking about teaching and learning techniques, not about helping with the problems directly. However the way I have re-written the question, seems to be a good match.
– ctrl-alt-delor
Nov 23 at 10:57