repeat a list of data in the same file/column












2














I have a list of data in a file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000


and I would like to repeat this sequence of data 35 times so to have an output file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000









share|improve this question
























  • Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
    – steeldriver
    Dec 23 at 17:59










  • Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
    – Sergiy Kolodyazhnyy
    Dec 23 at 22:23










  • In a cshell you can do simply: repeat 35 cat data_file
    – Rakesh Sharma
    20 hours ago


















2














I have a list of data in a file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000


and I would like to repeat this sequence of data 35 times so to have an output file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000









share|improve this question
























  • Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
    – steeldriver
    Dec 23 at 17:59










  • Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
    – Sergiy Kolodyazhnyy
    Dec 23 at 22:23










  • In a cshell you can do simply: repeat 35 cat data_file
    – Rakesh Sharma
    20 hours ago
















2












2








2







I have a list of data in a file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000


and I would like to repeat this sequence of data 35 times so to have an output file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000









share|improve this question















I have a list of data in a file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000


and I would like to repeat this sequence of data 35 times so to have an output file such as



-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.(x35 times)
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000






text-processing awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 23 at 18:58









Jeff Schaller

38.5k1053125




38.5k1053125










asked Dec 23 at 17:51









Dimitris Mintis

755




755












  • Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
    – steeldriver
    Dec 23 at 17:59










  • Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
    – Sergiy Kolodyazhnyy
    Dec 23 at 22:23










  • In a cshell you can do simply: repeat 35 cat data_file
    – Rakesh Sharma
    20 hours ago




















  • Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
    – steeldriver
    Dec 23 at 17:59










  • Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
    – Sergiy Kolodyazhnyy
    Dec 23 at 22:23










  • In a cshell you can do simply: repeat 35 cat data_file
    – Rakesh Sharma
    20 hours ago


















Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 at 17:59




Does it have to be awk? with perl, you could do something like perl -00 -ne 'print $_ x 35' file
– steeldriver
Dec 23 at 17:59












Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 at 22:23




Is that list the only contents of the original file ? Are the other things in the file that need to be filtered out ? Please clarify
– Sergiy Kolodyazhnyy
Dec 23 at 22:23












In a cshell you can do simply: repeat 35 cat data_file
– Rakesh Sharma
20 hours ago






In a cshell you can do simply: repeat 35 cat data_file
– Rakesh Sharma
20 hours ago












4 Answers
4






active

oldest

votes


















2














With simple for loop:



for i in {1..35}; do cat input_file >> new_file; done





share|improve this answer





















  • Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
    – Sergiy Kolodyazhnyy
    Dec 23 at 22:24



















2














For exactly that input data structure (i.e. no empty lines), and for awks that allow for it (i.e. the last line read is available in the END section), try



$ awk 'END {for (i=1; i=35; i++) print}' RS= file
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000
.
.
.
-0.2947990000000000
0.1722064000000000
0.1722064000000000
0.1722064000000000
0.0315420000000000


EDIT: or, even shorter,



awk 'END {for (i=35; i--;) print}' RS= file





share|improve this answer





























    0














    In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:



    awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt


    Of course, if the number of lines in file is very large it would be more appropriate to cat the file multiple times and append as shown in Roman's answer






    share|improve this answer





























      0














      yes input_file | sed 35q | xargs cat > output_file


      or with awk:



      awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
      awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        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%2f490634%2frepeat-a-list-of-data-in-the-same-file-column%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        With simple for loop:



        for i in {1..35}; do cat input_file >> new_file; done





        share|improve this answer





















        • Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
          – Sergiy Kolodyazhnyy
          Dec 23 at 22:24
















        2














        With simple for loop:



        for i in {1..35}; do cat input_file >> new_file; done





        share|improve this answer





















        • Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
          – Sergiy Kolodyazhnyy
          Dec 23 at 22:24














        2












        2








        2






        With simple for loop:



        for i in {1..35}; do cat input_file >> new_file; done





        share|improve this answer












        With simple for loop:



        for i in {1..35}; do cat input_file >> new_file; done






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 23 at 17:59









        RomanPerekhrest

        22.8k12346




        22.8k12346












        • Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
          – Sergiy Kolodyazhnyy
          Dec 23 at 22:24


















        • Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
          – Sergiy Kolodyazhnyy
          Dec 23 at 22:24
















        Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
        – Sergiy Kolodyazhnyy
        Dec 23 at 22:24




        Consider implementing the loop via while with counter. The {1..35} works in bash and ksh ( IIRC ) but not in POSIX /bin/sh.
        – Sergiy Kolodyazhnyy
        Dec 23 at 22:24













        2














        For exactly that input data structure (i.e. no empty lines), and for awks that allow for it (i.e. the last line read is available in the END section), try



        $ awk 'END {for (i=1; i=35; i++) print}' RS= file
        -0.2947990000000000
        0.1722064000000000
        0.1722064000000000
        0.1722064000000000
        0.0315420000000000
        .
        .
        .
        -0.2947990000000000
        0.1722064000000000
        0.1722064000000000
        0.1722064000000000
        0.0315420000000000


        EDIT: or, even shorter,



        awk 'END {for (i=35; i--;) print}' RS= file





        share|improve this answer


























          2














          For exactly that input data structure (i.e. no empty lines), and for awks that allow for it (i.e. the last line read is available in the END section), try



          $ awk 'END {for (i=1; i=35; i++) print}' RS= file
          -0.2947990000000000
          0.1722064000000000
          0.1722064000000000
          0.1722064000000000
          0.0315420000000000
          .
          .
          .
          -0.2947990000000000
          0.1722064000000000
          0.1722064000000000
          0.1722064000000000
          0.0315420000000000


          EDIT: or, even shorter,



          awk 'END {for (i=35; i--;) print}' RS= file





          share|improve this answer
























            2












            2








            2






            For exactly that input data structure (i.e. no empty lines), and for awks that allow for it (i.e. the last line read is available in the END section), try



            $ awk 'END {for (i=1; i=35; i++) print}' RS= file
            -0.2947990000000000
            0.1722064000000000
            0.1722064000000000
            0.1722064000000000
            0.0315420000000000
            .
            .
            .
            -0.2947990000000000
            0.1722064000000000
            0.1722064000000000
            0.1722064000000000
            0.0315420000000000


            EDIT: or, even shorter,



            awk 'END {for (i=35; i--;) print}' RS= file





            share|improve this answer












            For exactly that input data structure (i.e. no empty lines), and for awks that allow for it (i.e. the last line read is available in the END section), try



            $ awk 'END {for (i=1; i=35; i++) print}' RS= file
            -0.2947990000000000
            0.1722064000000000
            0.1722064000000000
            0.1722064000000000
            0.0315420000000000
            .
            .
            .
            -0.2947990000000000
            0.1722064000000000
            0.1722064000000000
            0.1722064000000000
            0.0315420000000000


            EDIT: or, even shorter,



            awk 'END {for (i=35; i--;) print}' RS= file






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 23 at 22:31









            RudiC

            4,1491312




            4,1491312























                0














                In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:



                awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt


                Of course, if the number of lines in file is very large it would be more appropriate to cat the file multiple times and append as shown in Roman's answer






                share|improve this answer


























                  0














                  In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:



                  awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt


                  Of course, if the number of lines in file is very large it would be more appropriate to cat the file multiple times and append as shown in Roman's answer






                  share|improve this answer
























                    0












                    0








                    0






                    In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:



                    awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt


                    Of course, if the number of lines in file is very large it would be more appropriate to cat the file multiple times and append as shown in Roman's answer






                    share|improve this answer












                    In awk this can be done via adding lines of file into array, and iterating through array via nested loop within END statement:



                    awk '{a[i++]=$0} END{ for(c=1;c<=35;c++) for(j=0;j<=i;j++) print a[j]}' data.txt


                    Of course, if the number of lines in file is very large it would be more appropriate to cat the file multiple times and append as shown in Roman's answer







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 23 at 22:31









                    Sergiy Kolodyazhnyy

                    8,27212152




                    8,27212152























                        0














                        yes input_file | sed 35q | xargs cat > output_file


                        or with awk:



                        awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
                        awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file





                        share|improve this answer




























                          0














                          yes input_file | sed 35q | xargs cat > output_file


                          or with awk:



                          awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
                          awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file





                          share|improve this answer


























                            0












                            0








                            0






                            yes input_file | sed 35q | xargs cat > output_file


                            or with awk:



                            awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
                            awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file





                            share|improve this answer














                            yes input_file | sed 35q | xargs cat > output_file


                            or with awk:



                            awk 'BEGIN{while(ARGC<36)ARGV[ARGC++]=ARGV[1]}1' input_file
                            awk 'BEGIN{f=ARGV[1]; for(i=35;i--;){while((getline <f) > 0) print; close(f)}}' input_file






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 2 days ago

























                            answered Dec 23 at 18:04









                            Uncle Billy

                            1935




                            1935






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490634%2frepeat-a-list-of-data-in-the-same-file-column%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Paul Cézanne

                                UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                                Angular material date-picker (MatDatepicker) auto completes the date on focus out