Add matching column from index file to a csv

The name of the pictureThe name of the pictureThe name of the pictureClash 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









share|improve this question



























    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









    share|improve this question

























      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









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 23 at 11:56









      msp9011

      3,46643862




      3,46643862










      asked Aug 23 at 11:13









      T-One

      536




      536




















          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).





          share|improve this answer






















          • 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

















          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.






          share|improve this answer



























            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





            share|improve this answer




















              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
              );



              );













               

              draft saved


              draft discarded


















              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






























              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).





              share|improve this answer






















              • 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














              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).





              share|improve this answer






















              • 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












              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).





              share|improve this answer














              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).






              share|improve this answer














              share|improve this answer



              share|improve this answer








              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
















              • 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












              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.






              share|improve this answer
























                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.






                share|improve this answer






















                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 23 at 12:04









                  oliv

                  1,026210




                  1,026210




















                      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





                      share|improve this answer
























                        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





                        share|improve this answer






















                          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





                          share|improve this answer












                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 23 at 12:04









                          RudiC

                          1,2168




                          1,2168



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)