How to do awk to do sorting between a txt file and a csv file?
Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
Here is the file that I am going to use:
file1.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544
file2.csv:
Date,JUPAS,UniType,DSE,PRA ,PE,SIP,BRA,DDI Group,IDAM,"Working line",,
14-Oct-16,6,HKU,MAT SS2,278,806,248,0,0,0,32907,,
14-Oct-16,8,HKU,CHN SS4,231,726,250,0,0,0,23953,,
14-Oct-16,10,HKU,ENG SS6,593,3,11,0,0,0,4511,,
14-Oct-16,12,HKU,PHY SS8,664,16,12,0,0,0,3946,,
14-Oct-16,7,HKU,BIO SS3,297,225,11,0,0,0,18281,,
14-Oct-16,9,CU,CHE SS1,371,145,23,191,0,0,40570,,
14-Oct-16,11,CU,BIO SS3,336,90,0,100,0,0,36141,,
14-Oct-16,13,CU,CHE SS1,358,116,19,276,0,0,41559,,
,Total,,,7581 ,265926 ,5404 ,1150 ,1347 ,309 ,1136379 ,,
,,,,,,,,,,,,
,,,,,,,,,,,,
Date,Vendor,DSE,Working line,,,,,,,,,
14-Oct-16,SKH,MAT SS,269339,,,,,,,,,
14-Oct-16,SKH,CHN SS,270038,,,,,,,,,
14-Oct-16,SKH,ENG SS,144931,,,,,,,,,
14-Oct-16,LTH,BIO SS,154598,,,,,,,,,
14-Oct-16,LTH,CHE SS (BRA),817,,,,,,,,,
14-Oct-16,LTH,BIO SS (BRA),333,,,,,,,,,
How can I sort the data from file2.csv that JUPAS column matched with JUPAS_N column of file1.txt and output the following result text file:
result.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544 36141
Here is what I have tried before:
awk -F "," 'NR==FNRa[$2]=$11;next print $0, a[$2]' file2.csv FS='[ -]' file1.txt > result.txt
After using the above code, what I got is a text file with the same content with file1.txt . What code should I change in order to get the expected result above? Or should I use the sed function to do that?
linux bash shell-script awk csv
add a comment |Â
up vote
-2
down vote
favorite
Here is the file that I am going to use:
file1.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544
file2.csv:
Date,JUPAS,UniType,DSE,PRA ,PE,SIP,BRA,DDI Group,IDAM,"Working line",,
14-Oct-16,6,HKU,MAT SS2,278,806,248,0,0,0,32907,,
14-Oct-16,8,HKU,CHN SS4,231,726,250,0,0,0,23953,,
14-Oct-16,10,HKU,ENG SS6,593,3,11,0,0,0,4511,,
14-Oct-16,12,HKU,PHY SS8,664,16,12,0,0,0,3946,,
14-Oct-16,7,HKU,BIO SS3,297,225,11,0,0,0,18281,,
14-Oct-16,9,CU,CHE SS1,371,145,23,191,0,0,40570,,
14-Oct-16,11,CU,BIO SS3,336,90,0,100,0,0,36141,,
14-Oct-16,13,CU,CHE SS1,358,116,19,276,0,0,41559,,
,Total,,,7581 ,265926 ,5404 ,1150 ,1347 ,309 ,1136379 ,,
,,,,,,,,,,,,
,,,,,,,,,,,,
Date,Vendor,DSE,Working line,,,,,,,,,
14-Oct-16,SKH,MAT SS,269339,,,,,,,,,
14-Oct-16,SKH,CHN SS,270038,,,,,,,,,
14-Oct-16,SKH,ENG SS,144931,,,,,,,,,
14-Oct-16,LTH,BIO SS,154598,,,,,,,,,
14-Oct-16,LTH,CHE SS (BRA),817,,,,,,,,,
14-Oct-16,LTH,BIO SS (BRA),333,,,,,,,,,
How can I sort the data from file2.csv that JUPAS column matched with JUPAS_N column of file1.txt and output the following result text file:
result.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544 36141
Here is what I have tried before:
awk -F "," 'NR==FNRa[$2]=$11;next print $0, a[$2]' file2.csv FS='[ -]' file1.txt > result.txt
After using the above code, what I got is a text file with the same content with file1.txt . What code should I change in order to get the expected result above? Or should I use the sed function to do that?
linux bash shell-script awk csv
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
JUPAS_N
infile 1
is11-2
andJUPAS
infile 2
is11
? it is correct?
â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
Here is the file that I am going to use:
file1.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544
file2.csv:
Date,JUPAS,UniType,DSE,PRA ,PE,SIP,BRA,DDI Group,IDAM,"Working line",,
14-Oct-16,6,HKU,MAT SS2,278,806,248,0,0,0,32907,,
14-Oct-16,8,HKU,CHN SS4,231,726,250,0,0,0,23953,,
14-Oct-16,10,HKU,ENG SS6,593,3,11,0,0,0,4511,,
14-Oct-16,12,HKU,PHY SS8,664,16,12,0,0,0,3946,,
14-Oct-16,7,HKU,BIO SS3,297,225,11,0,0,0,18281,,
14-Oct-16,9,CU,CHE SS1,371,145,23,191,0,0,40570,,
14-Oct-16,11,CU,BIO SS3,336,90,0,100,0,0,36141,,
14-Oct-16,13,CU,CHE SS1,358,116,19,276,0,0,41559,,
,Total,,,7581 ,265926 ,5404 ,1150 ,1347 ,309 ,1136379 ,,
,,,,,,,,,,,,
,,,,,,,,,,,,
Date,Vendor,DSE,Working line,,,,,,,,,
14-Oct-16,SKH,MAT SS,269339,,,,,,,,,
14-Oct-16,SKH,CHN SS,270038,,,,,,,,,
14-Oct-16,SKH,ENG SS,144931,,,,,,,,,
14-Oct-16,LTH,BIO SS,154598,,,,,,,,,
14-Oct-16,LTH,CHE SS (BRA),817,,,,,,,,,
14-Oct-16,LTH,BIO SS (BRA),333,,,,,,,,,
How can I sort the data from file2.csv that JUPAS column matched with JUPAS_N column of file1.txt and output the following result text file:
result.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544 36141
Here is what I have tried before:
awk -F "," 'NR==FNRa[$2]=$11;next print $0, a[$2]' file2.csv FS='[ -]' file1.txt > result.txt
After using the above code, what I got is a text file with the same content with file1.txt . What code should I change in order to get the expected result above? Or should I use the sed function to do that?
linux bash shell-script awk csv
Here is the file that I am going to use:
file1.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544
file2.csv:
Date,JUPAS,UniType,DSE,PRA ,PE,SIP,BRA,DDI Group,IDAM,"Working line",,
14-Oct-16,6,HKU,MAT SS2,278,806,248,0,0,0,32907,,
14-Oct-16,8,HKU,CHN SS4,231,726,250,0,0,0,23953,,
14-Oct-16,10,HKU,ENG SS6,593,3,11,0,0,0,4511,,
14-Oct-16,12,HKU,PHY SS8,664,16,12,0,0,0,3946,,
14-Oct-16,7,HKU,BIO SS3,297,225,11,0,0,0,18281,,
14-Oct-16,9,CU,CHE SS1,371,145,23,191,0,0,40570,,
14-Oct-16,11,CU,BIO SS3,336,90,0,100,0,0,36141,,
14-Oct-16,13,CU,CHE SS1,358,116,19,276,0,0,41559,,
,Total,,,7581 ,265926 ,5404 ,1150 ,1347 ,309 ,1136379 ,,
,,,,,,,,,,,,
,,,,,,,,,,,,
Date,Vendor,DSE,Working line,,,,,,,,,
14-Oct-16,SKH,MAT SS,269339,,,,,,,,,
14-Oct-16,SKH,CHN SS,270038,,,,,,,,,
14-Oct-16,SKH,ENG SS,144931,,,,,,,,,
14-Oct-16,LTH,BIO SS,154598,,,,,,,,,
14-Oct-16,LTH,CHE SS (BRA),817,,,,,,,,,
14-Oct-16,LTH,BIO SS (BRA),333,,,,,,,,,
How can I sort the data from file2.csv that JUPAS column matched with JUPAS_N column of file1.txt and output the following result text file:
result.txt:
School JUPAS_N Univ ID Working_line_number
TST 11-2 CUHK 90544 36141
Here is what I have tried before:
awk -F "," 'NR==FNRa[$2]=$11;next print $0, a[$2]' file2.csv FS='[ -]' file1.txt > result.txt
After using the above code, what I got is a text file with the same content with file1.txt . What code should I change in order to get the expected result above? Or should I use the sed function to do that?
linux bash shell-script awk csv
linux bash shell-script awk csv
asked 9 mins ago
Owen
92
92
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
JUPAS_N
infile 1
is11-2
andJUPAS
infile 2
is11
? it is correct?
â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago
add a comment |Â
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
JUPAS_N
infile 1
is11-2
andJUPAS
infile 2
is11
? it is correct?
â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
JUPAS_N
in file 1
is 11-2
and JUPAS
in file 2
is 11
? it is correct?â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago
JUPAS_N
in file 1
is 11-2
and JUPAS
in file 2
is 11
? it is correct?â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago
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%2f474947%2fhow-to-do-awk-to-do-sorting-between-a-txt-file-and-a-csv-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
Hello, @Owen the results in your question are not clear hw generated would you please elaborate more?
â Goro
6 mins ago
JUPAS_N
infile 1
is11-2
andJUPAS
infile 2
is11
? it is correct?â Ã¨Ã§Ã±Ã¾Ã§Ã¨Ã§Ã¨Ã§
5 mins ago