How can I use awk to get value multiple times from one file to other file?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
File1:
01 999 234 432 666
02 888 453 234 763
03 145 334 235 456
04 234 784 482 785
05 868 453 546 787
File2:
01
01
02
03
03
05
As I want to do matching between the first column of the 2 files and get the expected output as shown:
Expected Output:
999 234 432 666
999 234 432 666
888 453 234 763
145 334 235 456
145 334 235 456
868 453 546 787
And I tried the code below:
awk 'NR==FNRa[$1]=$1; next if($1 in a) print $2" "$3" "$4" "$5' file2 file1
however what I got is like that:
999 234 432 666
888 453 234 763
145 334 235 456
868 453 546 787
So How can I get the expected output by using awk?
linux shell-script awk
add a comment |Â
up vote
0
down vote
favorite
File1:
01 999 234 432 666
02 888 453 234 763
03 145 334 235 456
04 234 784 482 785
05 868 453 546 787
File2:
01
01
02
03
03
05
As I want to do matching between the first column of the 2 files and get the expected output as shown:
Expected Output:
999 234 432 666
999 234 432 666
888 453 234 763
145 334 235 456
145 334 235 456
868 453 546 787
And I tried the code below:
awk 'NR==FNRa[$1]=$1; next if($1 in a) print $2" "$3" "$4" "$5' file2 file1
however what I got is like that:
999 234 432 666
888 453 234 763
145 334 235 456
868 453 546 787
So How can I get the expected output by using awk?
linux shell-script awk
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
File1:
01 999 234 432 666
02 888 453 234 763
03 145 334 235 456
04 234 784 482 785
05 868 453 546 787
File2:
01
01
02
03
03
05
As I want to do matching between the first column of the 2 files and get the expected output as shown:
Expected Output:
999 234 432 666
999 234 432 666
888 453 234 763
145 334 235 456
145 334 235 456
868 453 546 787
And I tried the code below:
awk 'NR==FNRa[$1]=$1; next if($1 in a) print $2" "$3" "$4" "$5' file2 file1
however what I got is like that:
999 234 432 666
888 453 234 763
145 334 235 456
868 453 546 787
So How can I get the expected output by using awk?
linux shell-script awk
File1:
01 999 234 432 666
02 888 453 234 763
03 145 334 235 456
04 234 784 482 785
05 868 453 546 787
File2:
01
01
02
03
03
05
As I want to do matching between the first column of the 2 files and get the expected output as shown:
Expected Output:
999 234 432 666
999 234 432 666
888 453 234 763
145 334 235 456
145 334 235 456
868 453 546 787
And I tried the code below:
awk 'NR==FNRa[$1]=$1; next if($1 in a) print $2" "$3" "$4" "$5' file2 file1
however what I got is like that:
999 234 432 666
888 453 234 763
145 334 235 456
868 453 546 787
So How can I get the expected output by using awk?
linux shell-script awk
linux shell-script awk
asked 6 mins ago
Owen
483
483
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f480690%2fhow-can-i-use-awk-to-get-value-multiple-times-from-one-file-to-other-file%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