Turning data collected vertically to a table

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











up vote
5
down vote

favorite












I have data was collected and saved in file "data.txt", in the following format:



<$ MG_nr>
</200>company-type:Engine1
</210>company-name:STR
</220>address:XX
</230>nr:4568789
</240>zipcode:08765
</250>place:ljkmljubi
</260>phone:786754678
</270>fax:76756778
</$>
<$ MG_nr>
</280>company-type:Engine2
</290>company-name:STR
</300>address:XX
</310>nr:7675678
</320>zipcode:87867
</330>place:jkhgkl
</340>phone:87865
</350>fax:876578
</$>
<$ MG_nr>
</360>company-type:Engine3
</370>company-name:STR
</380>address:XX
</390>nr:78675467
</400>zipcode:87657
</410>place:uiytryui
</420>phone:87656788976
</430>fax:8976535467
</$>
<$ MG_nr>
</440>company-type:Engine4
</450>company-name:STR
</460>address:XX
</470>nr:876578y67
</480>zipcode:786578
</490>place:kljhgryui
</500>phone:8976546789
</510>fax:989765
</$>


I wanted to turn this to a spreadsheet like this:



Type Name Address Nr Zipcode Place Phone Fax
------------------------------------------------------------------------
Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


I tried this code which I found it on U & L site, and I tried to replicate it:



#!/bin/bash
cut -d'>' -f 2 data.txt | awk -F: '
/^company-type:/type[c]=$2
/^company-name:/name[c]=$2
/^address:/address[c]=$2
/^nr:/nr[c]=$2
/^zipcode:/zipcode[c]=$2
/^place:/place[c]=$2
/^phone:/phone[c]=$2
/^Fax:/fax[c]=$2;c++
END
print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"
for(x in type)
printf "%-10s %3d %s %s %s %s %s %sn",
substr(type[x],2),
company-name[x],
address[x],
nr[x],
zipcode[x],
place[x]
phone[x]
fax[x]

' data.txt


But this didn't work, it only prints the header!!!



print "Type Name Address Nr Zipcode Place Phone Fax"
print "------------------------------------------------------------------------"


I can't figure out what I am doing wrong?



I appreciate any advice! or any suggestion to make the code above works and simpler.










share|improve this question









New contributor




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























    up vote
    5
    down vote

    favorite












    I have data was collected and saved in file "data.txt", in the following format:



    <$ MG_nr>
    </200>company-type:Engine1
    </210>company-name:STR
    </220>address:XX
    </230>nr:4568789
    </240>zipcode:08765
    </250>place:ljkmljubi
    </260>phone:786754678
    </270>fax:76756778
    </$>
    <$ MG_nr>
    </280>company-type:Engine2
    </290>company-name:STR
    </300>address:XX
    </310>nr:7675678
    </320>zipcode:87867
    </330>place:jkhgkl
    </340>phone:87865
    </350>fax:876578
    </$>
    <$ MG_nr>
    </360>company-type:Engine3
    </370>company-name:STR
    </380>address:XX
    </390>nr:78675467
    </400>zipcode:87657
    </410>place:uiytryui
    </420>phone:87656788976
    </430>fax:8976535467
    </$>
    <$ MG_nr>
    </440>company-type:Engine4
    </450>company-name:STR
    </460>address:XX
    </470>nr:876578y67
    </480>zipcode:786578
    </490>place:kljhgryui
    </500>phone:8976546789
    </510>fax:989765
    </$>


    I wanted to turn this to a spreadsheet like this:



    Type Name Address Nr Zipcode Place Phone Fax
    ------------------------------------------------------------------------
    Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
    Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
    Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
    Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


    I tried this code which I found it on U & L site, and I tried to replicate it:



    #!/bin/bash
    cut -d'>' -f 2 data.txt | awk -F: '
    /^company-type:/type[c]=$2
    /^company-name:/name[c]=$2
    /^address:/address[c]=$2
    /^nr:/nr[c]=$2
    /^zipcode:/zipcode[c]=$2
    /^place:/place[c]=$2
    /^phone:/phone[c]=$2
    /^Fax:/fax[c]=$2;c++
    END
    print "Type Name Address Nr Zipcode Place Phone Fax"
    print "------------------------------------------------------------------------"
    for(x in type)
    printf "%-10s %3d %s %s %s %s %s %sn",
    substr(type[x],2),
    company-name[x],
    address[x],
    nr[x],
    zipcode[x],
    place[x]
    phone[x]
    fax[x]

    ' data.txt


    But this didn't work, it only prints the header!!!



    print "Type Name Address Nr Zipcode Place Phone Fax"
    print "------------------------------------------------------------------------"


    I can't figure out what I am doing wrong?



    I appreciate any advice! or any suggestion to make the code above works and simpler.










    share|improve this question









    New contributor




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





















      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I have data was collected and saved in file "data.txt", in the following format:



      <$ MG_nr>
      </200>company-type:Engine1
      </210>company-name:STR
      </220>address:XX
      </230>nr:4568789
      </240>zipcode:08765
      </250>place:ljkmljubi
      </260>phone:786754678
      </270>fax:76756778
      </$>
      <$ MG_nr>
      </280>company-type:Engine2
      </290>company-name:STR
      </300>address:XX
      </310>nr:7675678
      </320>zipcode:87867
      </330>place:jkhgkl
      </340>phone:87865
      </350>fax:876578
      </$>
      <$ MG_nr>
      </360>company-type:Engine3
      </370>company-name:STR
      </380>address:XX
      </390>nr:78675467
      </400>zipcode:87657
      </410>place:uiytryui
      </420>phone:87656788976
      </430>fax:8976535467
      </$>
      <$ MG_nr>
      </440>company-type:Engine4
      </450>company-name:STR
      </460>address:XX
      </470>nr:876578y67
      </480>zipcode:786578
      </490>place:kljhgryui
      </500>phone:8976546789
      </510>fax:989765
      </$>


      I wanted to turn this to a spreadsheet like this:



      Type Name Address Nr Zipcode Place Phone Fax
      ------------------------------------------------------------------------
      Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
      Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
      Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
      Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


      I tried this code which I found it on U & L site, and I tried to replicate it:



      #!/bin/bash
      cut -d'>' -f 2 data.txt | awk -F: '
      /^company-type:/type[c]=$2
      /^company-name:/name[c]=$2
      /^address:/address[c]=$2
      /^nr:/nr[c]=$2
      /^zipcode:/zipcode[c]=$2
      /^place:/place[c]=$2
      /^phone:/phone[c]=$2
      /^Fax:/fax[c]=$2;c++
      END
      print "Type Name Address Nr Zipcode Place Phone Fax"
      print "------------------------------------------------------------------------"
      for(x in type)
      printf "%-10s %3d %s %s %s %s %s %sn",
      substr(type[x],2),
      company-name[x],
      address[x],
      nr[x],
      zipcode[x],
      place[x]
      phone[x]
      fax[x]

      ' data.txt


      But this didn't work, it only prints the header!!!



      print "Type Name Address Nr Zipcode Place Phone Fax"
      print "------------------------------------------------------------------------"


      I can't figure out what I am doing wrong?



      I appreciate any advice! or any suggestion to make the code above works and simpler.










      share|improve this question









      New contributor




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











      I have data was collected and saved in file "data.txt", in the following format:



      <$ MG_nr>
      </200>company-type:Engine1
      </210>company-name:STR
      </220>address:XX
      </230>nr:4568789
      </240>zipcode:08765
      </250>place:ljkmljubi
      </260>phone:786754678
      </270>fax:76756778
      </$>
      <$ MG_nr>
      </280>company-type:Engine2
      </290>company-name:STR
      </300>address:XX
      </310>nr:7675678
      </320>zipcode:87867
      </330>place:jkhgkl
      </340>phone:87865
      </350>fax:876578
      </$>
      <$ MG_nr>
      </360>company-type:Engine3
      </370>company-name:STR
      </380>address:XX
      </390>nr:78675467
      </400>zipcode:87657
      </410>place:uiytryui
      </420>phone:87656788976
      </430>fax:8976535467
      </$>
      <$ MG_nr>
      </440>company-type:Engine4
      </450>company-name:STR
      </460>address:XX
      </470>nr:876578y67
      </480>zipcode:786578
      </490>place:kljhgryui
      </500>phone:8976546789
      </510>fax:989765
      </$>


      I wanted to turn this to a spreadsheet like this:



      Type Name Address Nr Zipcode Place Phone Fax
      ------------------------------------------------------------------------
      Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
      Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
      Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
      Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


      I tried this code which I found it on U & L site, and I tried to replicate it:



      #!/bin/bash
      cut -d'>' -f 2 data.txt | awk -F: '
      /^company-type:/type[c]=$2
      /^company-name:/name[c]=$2
      /^address:/address[c]=$2
      /^nr:/nr[c]=$2
      /^zipcode:/zipcode[c]=$2
      /^place:/place[c]=$2
      /^phone:/phone[c]=$2
      /^Fax:/fax[c]=$2;c++
      END
      print "Type Name Address Nr Zipcode Place Phone Fax"
      print "------------------------------------------------------------------------"
      for(x in type)
      printf "%-10s %3d %s %s %s %s %s %sn",
      substr(type[x],2),
      company-name[x],
      address[x],
      nr[x],
      zipcode[x],
      place[x]
      phone[x]
      fax[x]

      ' data.txt


      But this didn't work, it only prints the header!!!



      print "Type Name Address Nr Zipcode Place Phone Fax"
      print "------------------------------------------------------------------------"


      I can't figure out what I am doing wrong?



      I appreciate any advice! or any suggestion to make the code above works and simpler.







      awk cut text-formatting






      share|improve this question









      New contributor




      Nadal 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




      Nadal 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 2 hours ago





















      New contributor




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









      asked 4 hours ago









      Nadal

      455




      455




      New contributor




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





      New contributor





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






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




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          This is a simpler solution:



          awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t

          company-type company-name address nr zipcode place phone fax
          Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
          Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
          Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
          Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


          The field separator -F enables awk to read the data in columns based on : and >, then awk prints the third column which is equivalent to the required actual data, at the same time it construct the header.



          This output is piped to xargs which reorganizes it in eight columns. Finally, the command column adds tab and equal spaces between the resultant columns.






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



            );






            Nadal 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%2f475055%2fturning-data-collected-vertically-to-a-table%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            This is a simpler solution:



            awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t

            company-type company-name address nr zipcode place phone fax
            Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
            Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
            Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
            Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


            The field separator -F enables awk to read the data in columns based on : and >, then awk prints the third column which is equivalent to the required actual data, at the same time it construct the header.



            This output is piped to xargs which reorganizes it in eight columns. Finally, the command column adds tab and equal spaces between the resultant columns.






            share|improve this answer


























              up vote
              4
              down vote



              accepted










              This is a simpler solution:



              awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t

              company-type company-name address nr zipcode place phone fax
              Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
              Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
              Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
              Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


              The field separator -F enables awk to read the data in columns based on : and >, then awk prints the third column which is equivalent to the required actual data, at the same time it construct the header.



              This output is piped to xargs which reorganizes it in eight columns. Finally, the command column adds tab and equal spaces between the resultant columns.






              share|improve this answer
























                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                This is a simpler solution:



                awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t

                company-type company-name address nr zipcode place phone fax
                Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
                Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
                Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
                Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


                The field separator -F enables awk to read the data in columns based on : and >, then awk prints the third column which is equivalent to the required actual data, at the same time it construct the header.



                This output is piped to xargs which reorganizes it in eight columns. Finally, the command column adds tab and equal spaces between the resultant columns.






                share|improve this answer














                This is a simpler solution:



                awk -F'[>:]' 'BEGINprint "company-type company-name address nr zipcode place phone fax"print $3' data.txt | xargs -n8 | column -t

                company-type company-name address nr zipcode place phone fax
                Engine1 STR XX 4568789 08765 ljkmljubi 786754678 76756778
                Engine2 STR XX 7675678 87867 jkhgkl 87865 876578
                Engine3 STR XX 78675467 87657 uiytryui 87656788976 8976535467
                Engine4 STR XX 87657867 786578 kljhgryui 8976546789 989765


                The field separator -F enables awk to read the data in columns based on : and >, then awk prints the third column which is equivalent to the required actual data, at the same time it construct the header.



                This output is piped to xargs which reorganizes it in eight columns. Finally, the command column adds tab and equal spaces between the resultant columns.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 2 hours ago









                Goro

                8,70354384




                8,70354384




















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









                     

                    draft saved


                    draft discarded


















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












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











                    Nadal 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%2f475055%2fturning-data-collected-vertically-to-a-table%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    Installing NextGIS Connect into QGIS 3?

                    One-line joke