Add matching column from index file to a csv

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a file index.txt with data like:
2013/10/13-121 f19f26f09691c2429cb33456cf64f867
2013/10/17-131 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129 33f7592a4ad22f9f6d63d6a17782d023
......
And a second file in CSV format with data like:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
Now i need a solution to add the MD5SUM at the end of the CSV when the ID (first column) is a match in the index file or vice versa , so at the end the file should look like this:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
awk
add a comment |Â
up vote
1
down vote
favorite
I have a file index.txt with data like:
2013/10/13-121 f19f26f09691c2429cb33456cf64f867
2013/10/17-131 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129 33f7592a4ad22f9f6d63d6a17782d023
......
And a second file in CSV format with data like:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
Now i need a solution to add the MD5SUM at the end of the CSV when the ID (first column) is a match in the index file or vice versa , so at the end the file should look like this:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
awk
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a file index.txt with data like:
2013/10/13-121 f19f26f09691c2429cb33456cf64f867
2013/10/17-131 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129 33f7592a4ad22f9f6d63d6a17782d023
......
And a second file in CSV format with data like:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
Now i need a solution to add the MD5SUM at the end of the CSV when the ID (first column) is a match in the index file or vice versa , so at the end the file should look like this:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
awk
I have a file index.txt with data like:
2013/10/13-121 f19f26f09691c2429cb33456cf64f867
2013/10/17-131 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129 33f7592a4ad22f9f6d63d6a17782d023
......
And a second file in CSV format with data like:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965
Now i need a solution to add the MD5SUM at the end of the CSV when the ID (first column) is a match in the index file or vice versa , so at the end the file should look like this:
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
awk
awk
edited Aug 23 at 11:56
msp9011
3,46643862
3,46643862
asked Aug 23 at 11:13
T-One
536
536
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
Try with join command.
join <(sort file1.csv | sed 's/$/,/g') <(sort index.txt | sed 's/ /, /g')
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
sort t1 | sed 's/$/,/g'sort file1.csv and sufix it by comma.sort t2 | sed 's/ /, /g'sort index.txt and replace the delimitor- Then use join command (by default 1st field).
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
add a comment |Â
up vote
1
down vote
Using awk without sorting any file:
awk 'NR==FNRa[$1]=$2;next$(NF+1)=a[$1]1' index.txt FS=', ' OFS=', ' file.csv
The first block statement allows the first file index.txt to be copied into the array a.
The second block statement append the content of the array a at the end of the line of file file.csv if the key (first field of the file) is part of the array.
add a comment |Â
up vote
1
down vote
Try also - should IDs in first and second file differ - :
awk 'NR == FNR S[$1] = $2; next print $0 FS " " S[$1]' file1 FS="," file2
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Try with join command.
join <(sort file1.csv | sed 's/$/,/g') <(sort index.txt | sed 's/ /, /g')
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
sort t1 | sed 's/$/,/g'sort file1.csv and sufix it by comma.sort t2 | sed 's/ /, /g'sort index.txt and replace the delimitor- Then use join command (by default 1st field).
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
add a comment |Â
up vote
1
down vote
Try with join command.
join <(sort file1.csv | sed 's/$/,/g') <(sort index.txt | sed 's/ /, /g')
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
sort t1 | sed 's/$/,/g'sort file1.csv and sufix it by comma.sort t2 | sed 's/ /, /g'sort index.txt and replace the delimitor- Then use join command (by default 1st field).
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Try with join command.
join <(sort file1.csv | sed 's/$/,/g') <(sort index.txt | sed 's/ /, /g')
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
sort t1 | sed 's/$/,/g'sort file1.csv and sufix it by comma.sort t2 | sed 's/ /, /g'sort index.txt and replace the delimitor- Then use join command (by default 1st field).
Try with join command.
join <(sort file1.csv | sed 's/$/,/g') <(sort index.txt | sed 's/ /, /g')
2013/10/10-129, DLXDAE, 15:33, 18:46, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 33f7592a4ad22f9f6d63d6a17782d023
2013/10/13-121, DLDFWSXDR, 15:33, 18:21, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, f19f26f09691c2429cb33456cf64f867
2013/10/17-131, DLDFWXDR, 11:05, 15:08, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 583d3936c814c1bf4e663fe1688fe4a3
2013/10/20-106, DLSDXDR, 12:08, 13:06, Normal, No, 5F2B0121-4F2B-481D-B79F-2DC827B85093/22551965, 0f7082e2bb7224aad0bd7a6401532f56
sort t1 | sed 's/$/,/g'sort file1.csv and sufix it by comma.sort t2 | sed 's/ /, /g'sort index.txt and replace the delimitor- Then use join command (by default 1st field).
edited Aug 23 at 11:53
answered Aug 23 at 11:26
msp9011
3,46643862
3,46643862
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
add a comment |Â
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Brilliant if IDs and their count are identical; what if they differ?
â RudiC
Aug 23 at 12:04
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
Thanks RudiC, thats exactly the point, the Index file i have has 11785 uniq IDs and the csv has 139898 lines with multiple same IDs.
â T-One
Aug 24 at 11:11
add a comment |Â
up vote
1
down vote
Using awk without sorting any file:
awk 'NR==FNRa[$1]=$2;next$(NF+1)=a[$1]1' index.txt FS=', ' OFS=', ' file.csv
The first block statement allows the first file index.txt to be copied into the array a.
The second block statement append the content of the array a at the end of the line of file file.csv if the key (first field of the file) is part of the array.
add a comment |Â
up vote
1
down vote
Using awk without sorting any file:
awk 'NR==FNRa[$1]=$2;next$(NF+1)=a[$1]1' index.txt FS=', ' OFS=', ' file.csv
The first block statement allows the first file index.txt to be copied into the array a.
The second block statement append the content of the array a at the end of the line of file file.csv if the key (first field of the file) is part of the array.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Using awk without sorting any file:
awk 'NR==FNRa[$1]=$2;next$(NF+1)=a[$1]1' index.txt FS=', ' OFS=', ' file.csv
The first block statement allows the first file index.txt to be copied into the array a.
The second block statement append the content of the array a at the end of the line of file file.csv if the key (first field of the file) is part of the array.
Using awk without sorting any file:
awk 'NR==FNRa[$1]=$2;next$(NF+1)=a[$1]1' index.txt FS=', ' OFS=', ' file.csv
The first block statement allows the first file index.txt to be copied into the array a.
The second block statement append the content of the array a at the end of the line of file file.csv if the key (first field of the file) is part of the array.
answered Aug 23 at 12:04
oliv
1,026210
1,026210
add a comment |Â
add a comment |Â
up vote
1
down vote
Try also - should IDs in first and second file differ - :
awk 'NR == FNR S[$1] = $2; next print $0 FS " " S[$1]' file1 FS="," file2
add a comment |Â
up vote
1
down vote
Try also - should IDs in first and second file differ - :
awk 'NR == FNR S[$1] = $2; next print $0 FS " " S[$1]' file1 FS="," file2
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Try also - should IDs in first and second file differ - :
awk 'NR == FNR S[$1] = $2; next print $0 FS " " S[$1]' file1 FS="," file2
Try also - should IDs in first and second file differ - :
awk 'NR == FNR S[$1] = $2; next print $0 FS " " S[$1]' file1 FS="," file2
answered Aug 23 at 12:04
RudiC
1,2168
1,2168
add a comment |Â
add a comment |Â
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%2f464366%2fadd-matching-column-from-index-file-to-a-csv%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