How to move every group of rows to a new column?

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











up vote
2
down vote

favorite












I'd like to move every group of rows to columns this way.



Input:



R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3


Output:



R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3


I'm also adding actual example with some number below.



Input:



8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10


Output:



8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10






share|improve this question


















  • 1




    Have you actually tried anything?
    – Nasir Riley
    Sep 2 at 22:56














up vote
2
down vote

favorite












I'd like to move every group of rows to columns this way.



Input:



R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3


Output:



R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3


I'm also adding actual example with some number below.



Input:



8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10


Output:



8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10






share|improve this question


















  • 1




    Have you actually tried anything?
    – Nasir Riley
    Sep 2 at 22:56












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'd like to move every group of rows to columns this way.



Input:



R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3


Output:



R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3


I'm also adding actual example with some number below.



Input:



8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10


Output:



8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10






share|improve this question














I'd like to move every group of rows to columns this way.



Input:



R1C1
R2C1
R3C1
R1C2
R2C2
R3C2
R1C3
R2C3
R3C3


Output:



R1C1 R1C2 R1C3
R2C1 R2C2 R2C3
R3C1 R3C2 R3C3


I'm also adding actual example with some number below.



Input:



8.097e-10
7.099e-10
6.638e-10
6.395e-10
6.258e-10
6.180e-10
6.134e-10
6.108e-10
6.093e-10


Output:



8.097e-10 6.395e-10 6.134e-10
7.099e-10 6.258e-10 6.108e-10
6.638e-10 6.180e-10 6.093e-10








share|improve this question













share|improve this question




share|improve this question








edited yesterday









αғsнιη

15.6k92563




15.6k92563










asked Sep 2 at 22:40









funfun

111




111







  • 1




    Have you actually tried anything?
    – Nasir Riley
    Sep 2 at 22:56












  • 1




    Have you actually tried anything?
    – Nasir Riley
    Sep 2 at 22:56







1




1




Have you actually tried anything?
– Nasir Riley
Sep 2 at 22:56




Have you actually tried anything?
– Nasir Riley
Sep 2 at 22:56










3 Answers
3






active

oldest

votes

















up vote
5
down vote













You can use the pr command:



pr -T -3 input_file > output_file



  • -3 means there'll be 3 columns


  • -T omits pagination of output





share|improve this answer



























    up vote
    3
    down vote













    If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3



    awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
    R1C1 R1C2 R1C3
    R2C1 R2C2 R2C3
    R3C1 R3C2 R3C3


    If the rs (reshape) utility is available, then



    rs 0 3 < file | rs -T


    or



    paste - - - < file | rs -c -T





    share|improve this answer



























      up vote
      0
      down vote













      $ cat test.txt
      R1C1
      R2C1
      R3C1
      R1C2
      R2C2
      R3C2
      R1C3
      R2C3
      R3C3

      $ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
      R1C1 R1C2 R1C3
      R2C1 R2C2 R2C3
      R3C1 R3C2 R3C3





      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%2f466465%2fhow-to-move-every-group-of-rows-to-a-new-column%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
        5
        down vote













        You can use the pr command:



        pr -T -3 input_file > output_file



        • -3 means there'll be 3 columns


        • -T omits pagination of output





        share|improve this answer
























          up vote
          5
          down vote













          You can use the pr command:



          pr -T -3 input_file > output_file



          • -3 means there'll be 3 columns


          • -T omits pagination of output





          share|improve this answer






















            up vote
            5
            down vote










            up vote
            5
            down vote









            You can use the pr command:



            pr -T -3 input_file > output_file



            • -3 means there'll be 3 columns


            • -T omits pagination of output





            share|improve this answer












            You can use the pr command:



            pr -T -3 input_file > output_file



            • -3 means there'll be 3 columns


            • -T omits pagination of output






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 2 at 22:53









            choroba

            24.5k34168




            24.5k34168






















                up vote
                3
                down vote













                If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3



                awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
                R1C1 R1C2 R1C3
                R2C1 R2C2 R2C3
                R3C1 R3C2 R3C3


                If the rs (reshape) utility is available, then



                rs 0 3 < file | rs -T


                or



                paste - - - < file | rs -c -T





                share|improve this answer
























                  up vote
                  3
                  down vote













                  If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3



                  awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
                  R1C1 R1C2 R1C3
                  R2C1 R2C2 R2C3
                  R3C1 R3C2 R3C3


                  If the rs (reshape) utility is available, then



                  rs 0 3 < file | rs -T


                  or



                  paste - - - < file | rs -c -T





                  share|improve this answer






















                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3



                    awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
                    R1C1 R1C2 R1C3
                    R2C1 R2C2 R2C3
                    R3C1 R3C2 R3C3


                    If the rs (reshape) utility is available, then



                    rs 0 3 < file | rs -T


                    or



                    paste - - - < file | rs -c -T





                    share|improve this answer












                    If you really need to do it with awk, then maybe use an array indexed by the record number modulo 3



                    awk 'i = (NR-1)%3; a[i] = a[i]? a[i] OFS $0 : $0 ENDfor(i=0;i<3;i++) print a[i]' file
                    R1C1 R1C2 R1C3
                    R2C1 R2C2 R2C3
                    R3C1 R3C2 R3C3


                    If the rs (reshape) utility is available, then



                    rs 0 3 < file | rs -T


                    or



                    paste - - - < file | rs -c -T






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 2 at 23:21









                    steeldriver

                    32.1k34979




                    32.1k34979




















                        up vote
                        0
                        down vote













                        $ cat test.txt
                        R1C1
                        R2C1
                        R3C1
                        R1C2
                        R2C2
                        R3C2
                        R1C3
                        R2C3
                        R3C3

                        $ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
                        R1C1 R1C2 R1C3
                        R2C1 R2C2 R2C3
                        R3C1 R3C2 R3C3





                        share|improve this answer
























                          up vote
                          0
                          down vote













                          $ cat test.txt
                          R1C1
                          R2C1
                          R3C1
                          R1C2
                          R2C2
                          R3C2
                          R1C3
                          R2C3
                          R3C3

                          $ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
                          R1C1 R1C2 R1C3
                          R2C1 R2C2 R2C3
                          R3C1 R3C2 R3C3





                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            $ cat test.txt
                            R1C1
                            R2C1
                            R3C1
                            R1C2
                            R2C2
                            R3C2
                            R1C3
                            R2C3
                            R3C3

                            $ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
                            R1C1 R1C2 R1C3
                            R2C1 R2C2 R2C3
                            R3C1 R3C2 R3C3





                            share|improve this answer












                            $ cat test.txt
                            R1C1
                            R2C1
                            R3C1
                            R1C2
                            R2C2
                            R3C2
                            R1C3
                            R2C3
                            R3C3

                            $ awk 'Arr[substr($0,1,2)]=Arr[substr($0,1,2)]" "$0ENDfor (i in Arr)print Arr[i]' test.txt
                            R1C1 R1C2 R1C3
                            R2C1 R2C2 R2C3
                            R3C1 R3C2 R3C3






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Sep 3 at 3:45









                            Kamaraj

                            2,7101312




                            2,7101312



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466465%2fhow-to-move-every-group-of-rows-to-a-new-column%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