How to Substitute columns with sed

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have 2 txt files that read like this



12345;Mary;3;2;36
35248;Joe;5;10;2
42579;Ruth;4;5;8


And



2018 10 19;35248;;6;4.2


What I need, and have been unable do is update the first file with the second. When the 1st column of file 1 matches with the 2nd of file two, file one is supposed to add 1 to the 3rd column, 6 to the 4th and 4.2 to the 5th.



Desired output:



35248;Joe;6;16;6.2


I have tried using sed but it doesn't work. What I have at the moment is this:



 if [ -e file2.txt ]; then
cat file2.txt | while read line; do
id=$(echo $line | cut -d';' -f2);
m=$(echo $line | cut -d';' -f5);
p=$(echo $line | cut -d';' -f4);
grep "$id" file1.txt | sed 's/

else
echo "No pending updates."


Thank you









share







New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • @user315713 your question is not formatted well. Can you fix that?
    – V13
    4 mins ago










  • Hi @Goro I added the last 2 columns of each file and added 1 to the other
    – user315713
    3 mins ago










  • @V13 What is not well?
    – user315713
    2 mins ago










  • the last chunk of code stops after "s/".
    – V13
    1 min ago










  • That's because all i tried didn't work, I have nothig there @V13
    – user315713
    18 secs ago














up vote
0
down vote

favorite












I have 2 txt files that read like this



12345;Mary;3;2;36
35248;Joe;5;10;2
42579;Ruth;4;5;8


And



2018 10 19;35248;;6;4.2


What I need, and have been unable do is update the first file with the second. When the 1st column of file 1 matches with the 2nd of file two, file one is supposed to add 1 to the 3rd column, 6 to the 4th and 4.2 to the 5th.



Desired output:



35248;Joe;6;16;6.2


I have tried using sed but it doesn't work. What I have at the moment is this:



 if [ -e file2.txt ]; then
cat file2.txt | while read line; do
id=$(echo $line | cut -d';' -f2);
m=$(echo $line | cut -d';' -f5);
p=$(echo $line | cut -d';' -f4);
grep "$id" file1.txt | sed 's/

else
echo "No pending updates."


Thank you









share







New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • @user315713 your question is not formatted well. Can you fix that?
    – V13
    4 mins ago










  • Hi @Goro I added the last 2 columns of each file and added 1 to the other
    – user315713
    3 mins ago










  • @V13 What is not well?
    – user315713
    2 mins ago










  • the last chunk of code stops after "s/".
    – V13
    1 min ago










  • That's because all i tried didn't work, I have nothig there @V13
    – user315713
    18 secs ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have 2 txt files that read like this



12345;Mary;3;2;36
35248;Joe;5;10;2
42579;Ruth;4;5;8


And



2018 10 19;35248;;6;4.2


What I need, and have been unable do is update the first file with the second. When the 1st column of file 1 matches with the 2nd of file two, file one is supposed to add 1 to the 3rd column, 6 to the 4th and 4.2 to the 5th.



Desired output:



35248;Joe;6;16;6.2


I have tried using sed but it doesn't work. What I have at the moment is this:



 if [ -e file2.txt ]; then
cat file2.txt | while read line; do
id=$(echo $line | cut -d';' -f2);
m=$(echo $line | cut -d';' -f5);
p=$(echo $line | cut -d';' -f4);
grep "$id" file1.txt | sed 's/

else
echo "No pending updates."


Thank you









share







New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have 2 txt files that read like this



12345;Mary;3;2;36
35248;Joe;5;10;2
42579;Ruth;4;5;8


And



2018 10 19;35248;;6;4.2


What I need, and have been unable do is update the first file with the second. When the 1st column of file 1 matches with the 2nd of file two, file one is supposed to add 1 to the 3rd column, 6 to the 4th and 4.2 to the 5th.



Desired output:



35248;Joe;6;16;6.2


I have tried using sed but it doesn't work. What I have at the moment is this:



 if [ -e file2.txt ]; then
cat file2.txt | while read line; do
id=$(echo $line | cut -d';' -f2);
m=$(echo $line | cut -d';' -f5);
p=$(echo $line | cut -d';' -f4);
grep "$id" file1.txt | sed 's/

else
echo "No pending updates."


Thank you







linux shell-script





share







New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 9 mins ago









user315713

1




1




New contributor




user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user315713 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • @user315713 your question is not formatted well. Can you fix that?
    – V13
    4 mins ago










  • Hi @Goro I added the last 2 columns of each file and added 1 to the other
    – user315713
    3 mins ago










  • @V13 What is not well?
    – user315713
    2 mins ago










  • the last chunk of code stops after "s/".
    – V13
    1 min ago










  • That's because all i tried didn't work, I have nothig there @V13
    – user315713
    18 secs ago
















  • @user315713 your question is not formatted well. Can you fix that?
    – V13
    4 mins ago










  • Hi @Goro I added the last 2 columns of each file and added 1 to the other
    – user315713
    3 mins ago










  • @V13 What is not well?
    – user315713
    2 mins ago










  • the last chunk of code stops after "s/".
    – V13
    1 min ago










  • That's because all i tried didn't work, I have nothig there @V13
    – user315713
    18 secs ago















@user315713 your question is not formatted well. Can you fix that?
– V13
4 mins ago




@user315713 your question is not formatted well. Can you fix that?
– V13
4 mins ago












Hi @Goro I added the last 2 columns of each file and added 1 to the other
– user315713
3 mins ago




Hi @Goro I added the last 2 columns of each file and added 1 to the other
– user315713
3 mins ago












@V13 What is not well?
– user315713
2 mins ago




@V13 What is not well?
– user315713
2 mins ago












the last chunk of code stops after "s/".
– V13
1 min ago




the last chunk of code stops after "s/".
– V13
1 min ago












That's because all i tried didn't work, I have nothig there @V13
– user315713
18 secs ago




That's because all i tried didn't work, I have nothig there @V13
– user315713
18 secs ago















active

oldest

votes











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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






user315713 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475325%2fhow-to-substitute-columns-with-sed%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








user315713 is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















user315713 is a new contributor. Be nice, and check out our Code of Conduct.












user315713 is a new contributor. Be nice, and check out our Code of Conduct.











user315713 is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475325%2fhow-to-substitute-columns-with-sed%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay