How to Substitute columns with sed
Clash 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
linux shell-script
New contributor
add a comment |Â
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
linux shell-script
New contributor
@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
add a comment |Â
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
linux shell-script
New contributor
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
linux shell-script
New contributor
New contributor
New contributor
asked 9 mins ago
user315713
1
1
New contributor
New contributor
@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
add a comment |Â
@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
add a comment |Â
active
oldest
votes
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.
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.
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
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
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
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
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
@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