Attach session numbers to its relevant IDs

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have long records were collected as an output of a code,



Part1=STS768976N-4BT345432-X00001-87675789AAAS Session=9
Part2=STS876578N-2BT234522-X00002-23456789UJHG Session=10
Part3=ST9876887N-1BT876577-X00003-65778978KJUH Session=11
Session=10 70000
Session=11 80000
Session=9 90000


I want to organize the data like this



Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000


how can i do that










share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    2
    down vote

    favorite












    I have long records were collected as an output of a code,



    Part1=STS768976N-4BT345432-X00001-87675789AAAS Session=9
    Part2=STS876578N-2BT234522-X00002-23456789UJHG Session=10
    Part3=ST9876887N-1BT876577-X00003-65778978KJUH Session=11
    Session=10 70000
    Session=11 80000
    Session=9 90000


    I want to organize the data like this



    Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
    Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
    Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000


    how can i do that










    share|improve this question









    New contributor




    Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have long records were collected as an output of a code,



      Part1=STS768976N-4BT345432-X00001-87675789AAAS Session=9
      Part2=STS876578N-2BT234522-X00002-23456789UJHG Session=10
      Part3=ST9876887N-1BT876577-X00003-65778978KJUH Session=11
      Session=10 70000
      Session=11 80000
      Session=9 90000


      I want to organize the data like this



      Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
      Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
      Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000


      how can i do that










      share|improve this question









      New contributor




      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have long records were collected as an output of a code,



      Part1=STS768976N-4BT345432-X00001-87675789AAAS Session=9
      Part2=STS876578N-2BT234522-X00002-23456789UJHG Session=10
      Part3=ST9876887N-1BT876577-X00003-65778978KJUH Session=11
      Session=10 70000
      Session=11 80000
      Session=9 90000


      I want to organize the data like this



      Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
      Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
      Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000


      how can i do that







      text-processing text-formatting






      share|improve this question









      New contributor




      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 3 hours ago









      Jeff Schaller

      33.8k851113




      33.8k851113






      New contributor




      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      Simon Q

      453




      453




      New contributor




      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          awk can do it:



          awk '/Part/i[$2]=$1;next$1 in iprint i[$1],$2' file | sort -t= -k1

          Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
          Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
          Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000





          share|improve this answer



























            up vote
            2
            down vote













            This approach takes 2 passes over the file: once to collect the ids, then again to print the results



            awk '
            NR==FNR if (/^Session=/) id[$1] = $2; next
            /^Part/ $NF = id[$NF]; print
            ' file file





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



              );






              Simon Q is a new contributor. Be nice, and check out our Code of Conduct.









               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474936%2fattach-session-numbers-to-its-relevant-ids%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              awk can do it:



              awk '/Part/i[$2]=$1;next$1 in iprint i[$1],$2' file | sort -t= -k1

              Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
              Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
              Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000





              share|improve this answer
























                up vote
                3
                down vote



                accepted










                awk can do it:



                awk '/Part/i[$2]=$1;next$1 in iprint i[$1],$2' file | sort -t= -k1

                Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
                Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
                Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000





                share|improve this answer






















                  up vote
                  3
                  down vote



                  accepted







                  up vote
                  3
                  down vote



                  accepted






                  awk can do it:



                  awk '/Part/i[$2]=$1;next$1 in iprint i[$1],$2' file | sort -t= -k1

                  Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
                  Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
                  Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000





                  share|improve this answer












                  awk can do it:



                  awk '/Part/i[$2]=$1;next$1 in iprint i[$1],$2' file | sort -t= -k1

                  Part1=STS768976N-4BT345432-X00001-87675789AAAS 90000
                  Part2=STS876578N-2BT234522-X00002-23456789UJHG 70000
                  Part3=ST9876887N-1BT876577-X00003-65778978KJUH 80000






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  Goro

                  8,57754384




                  8,57754384






















                      up vote
                      2
                      down vote













                      This approach takes 2 passes over the file: once to collect the ids, then again to print the results



                      awk '
                      NR==FNR if (/^Session=/) id[$1] = $2; next
                      /^Part/ $NF = id[$NF]; print
                      ' file file





                      share|improve this answer
























                        up vote
                        2
                        down vote













                        This approach takes 2 passes over the file: once to collect the ids, then again to print the results



                        awk '
                        NR==FNR if (/^Session=/) id[$1] = $2; next
                        /^Part/ $NF = id[$NF]; print
                        ' file file





                        share|improve this answer






















                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          This approach takes 2 passes over the file: once to collect the ids, then again to print the results



                          awk '
                          NR==FNR if (/^Session=/) id[$1] = $2; next
                          /^Part/ $NF = id[$NF]; print
                          ' file file





                          share|improve this answer












                          This approach takes 2 passes over the file: once to collect the ids, then again to print the results



                          awk '
                          NR==FNR if (/^Session=/) id[$1] = $2; next
                          /^Part/ $NF = id[$NF]; print
                          ' file file






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 1 hour ago









                          glenn jackman

                          48.8k466105




                          48.8k466105




















                              Simon Q is a new contributor. Be nice, and check out our Code of Conduct.









                               

                              draft saved


                              draft discarded


















                              Simon Q is a new contributor. Be nice, and check out our Code of Conduct.












                              Simon Q is a new contributor. Be nice, and check out our Code of Conduct.











                              Simon Q is a new contributor. Be nice, and check out our Code of Conduct.













                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474936%2fattach-session-numbers-to-its-relevant-ids%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              Long meetings (6-7 hours a day): Being “babysat” by supervisor

                              Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                              Confectionery