How to combine alternate lines in a file?

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











up vote
1
down vote

favorite
2












I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.



INPUT:
Tom
Nathan
Jack
Polo

Desired Output:
Tom Jack
Nathan Polo


One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.







share|improve this question
























    up vote
    1
    down vote

    favorite
    2












    I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.



    INPUT:
    Tom
    Nathan
    Jack
    Polo

    Desired Output:
    Tom Jack
    Nathan Polo


    One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.







    share|improve this question






















      up vote
      1
      down vote

      favorite
      2









      up vote
      1
      down vote

      favorite
      2






      2





      I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.



      INPUT:
      Tom
      Nathan
      Jack
      Polo

      Desired Output:
      Tom Jack
      Nathan Polo


      One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.







      share|improve this question












      I have a 4 line input file and i need to modify the file to combine alternate lines. I want to perform the operation in place.



      INPUT:
      Tom
      Nathan
      Jack
      Polo

      Desired Output:
      Tom Jack
      Nathan Polo


      One way is to collect odd numbered lines and flip them and cut even numbered lines and combine both files to get the final output. But i am looking for a simpler solution.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 12 at 19:55









      ayrton_senna

      4922416




      4922416




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Given



          $ cat INPUT
          Tom
          Nathan
          Jack
          Polo


          then



          $ pr -s -T -2 < INPUT
          Tom Jack
          Nathan Polo


          (paginate with single tab spacing between columns, no headers, two columns); or



          $ paste -d ' ' - - < INPUT | rs -T
          Tom Jack
          Nathan Polo


          (paste then transpose)






          share|improve this answer






















          • What package provides the rs command?
            – Wildcard
            Jan 12 at 23:19










          • @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
            – steeldriver
            Jan 12 at 23:24










          • Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
            – Wildcard
            Jan 12 at 23:34

















          up vote
          0
          down vote













          I have used below command to get the same.



          I accept its complex one when compared to pr. But this is my try



          for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab


          output



          Tom Jack
          Nathan Polo





          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%2f416663%2fhow-to-combine-alternate-lines-in-a-file%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
            5
            down vote



            accepted










            Given



            $ cat INPUT
            Tom
            Nathan
            Jack
            Polo


            then



            $ pr -s -T -2 < INPUT
            Tom Jack
            Nathan Polo


            (paginate with single tab spacing between columns, no headers, two columns); or



            $ paste -d ' ' - - < INPUT | rs -T
            Tom Jack
            Nathan Polo


            (paste then transpose)






            share|improve this answer






















            • What package provides the rs command?
              – Wildcard
              Jan 12 at 23:19










            • @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
              – steeldriver
              Jan 12 at 23:24










            • Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
              – Wildcard
              Jan 12 at 23:34














            up vote
            5
            down vote



            accepted










            Given



            $ cat INPUT
            Tom
            Nathan
            Jack
            Polo


            then



            $ pr -s -T -2 < INPUT
            Tom Jack
            Nathan Polo


            (paginate with single tab spacing between columns, no headers, two columns); or



            $ paste -d ' ' - - < INPUT | rs -T
            Tom Jack
            Nathan Polo


            (paste then transpose)






            share|improve this answer






















            • What package provides the rs command?
              – Wildcard
              Jan 12 at 23:19










            • @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
              – steeldriver
              Jan 12 at 23:24










            • Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
              – Wildcard
              Jan 12 at 23:34












            up vote
            5
            down vote



            accepted







            up vote
            5
            down vote



            accepted






            Given



            $ cat INPUT
            Tom
            Nathan
            Jack
            Polo


            then



            $ pr -s -T -2 < INPUT
            Tom Jack
            Nathan Polo


            (paginate with single tab spacing between columns, no headers, two columns); or



            $ paste -d ' ' - - < INPUT | rs -T
            Tom Jack
            Nathan Polo


            (paste then transpose)






            share|improve this answer














            Given



            $ cat INPUT
            Tom
            Nathan
            Jack
            Polo


            then



            $ pr -s -T -2 < INPUT
            Tom Jack
            Nathan Polo


            (paginate with single tab spacing between columns, no headers, two columns); or



            $ paste -d ' ' - - < INPUT | rs -T
            Tom Jack
            Nathan Polo


            (paste then transpose)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 12 at 22:55

























            answered Jan 12 at 20:03









            steeldriver

            31.6k34979




            31.6k34979











            • What package provides the rs command?
              – Wildcard
              Jan 12 at 23:19










            • @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
              – steeldriver
              Jan 12 at 23:24










            • Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
              – Wildcard
              Jan 12 at 23:34
















            • What package provides the rs command?
              – Wildcard
              Jan 12 at 23:19










            • @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
              – steeldriver
              Jan 12 at 23:24










            • Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
              – Wildcard
              Jan 12 at 23:34















            What package provides the rs command?
            – Wildcard
            Jan 12 at 23:19




            What package provides the rs command?
            – Wildcard
            Jan 12 at 23:19












            @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
            – steeldriver
            Jan 12 at 23:24




            @Wildcard on Ubuntu (so I guess other Debian-based systems) it has its own package called simply rs - my understanding is that it's originally a BSD utility so it may be packaged as such on other platforms?
            – steeldriver
            Jan 12 at 23:24












            Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
            – Wildcard
            Jan 12 at 23:34




            Interesting. Yes, it's pre-installed on Mac OS X (which uses BSD tools) but doesn't seem to exist at all for RHEL/CentOS.
            – Wildcard
            Jan 12 at 23:34












            up vote
            0
            down vote













            I have used below command to get the same.



            I accept its complex one when compared to pr. But this is my try



            for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab


            output



            Tom Jack
            Nathan Polo





            share|improve this answer
























              up vote
              0
              down vote













              I have used below command to get the same.



              I accept its complex one when compared to pr. But this is my try



              for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab


              output



              Tom Jack
              Nathan Polo





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I have used below command to get the same.



                I accept its complex one when compared to pr. But this is my try



                for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab


                output



                Tom Jack
                Nathan Polo





                share|improve this answer












                I have used below command to get the same.



                I accept its complex one when compared to pr. But this is my try



                for i in `sed -n '1~2p' l.txt`;do sed -n "/$i/,+1p" l.txt; done| split -l 2 |paste xaa xab


                output



                Tom Jack
                Nathan Polo






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 13 at 4:38









                Praveen Kumar BS

                1,010128




                1,010128






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416663%2fhow-to-combine-alternate-lines-in-a-file%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Christian Cage

                    How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?