How can I add 10 lines from a file (file2) to another one after 2 lines (file1)?











up vote
2
down vote

favorite












I have two different files separated by Tab. File 1 looks like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YMR325W 6.2822794040082 6.46992587787936 7.00507748994596


File 2 looks like this:



YLR177W 11.321823973245 12.1264440368589    11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998


What I'm trying to do right now is to add 10 lines from File 2 to File 1 after 2 lines. It should look like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
YLR177W 11.321823973245 12.1264440368589 11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405


So, basically, I'm trying to move 10 lines from File 2 between each transcr_ keeping the already existent line that is already below each transcr_.










share|improve this question









New contributor




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




















  • Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
    – fra-san
    1 hour ago






  • 1




    there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
    – Jeff Schaller
    1 hour ago















up vote
2
down vote

favorite












I have two different files separated by Tab. File 1 looks like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YMR325W 6.2822794040082 6.46992587787936 7.00507748994596


File 2 looks like this:



YLR177W 11.321823973245 12.1264440368589    11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998


What I'm trying to do right now is to add 10 lines from File 2 to File 1 after 2 lines. It should look like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
YLR177W 11.321823973245 12.1264440368589 11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405


So, basically, I'm trying to move 10 lines from File 2 between each transcr_ keeping the already existent line that is already below each transcr_.










share|improve this question









New contributor




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




















  • Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
    – fra-san
    1 hour ago






  • 1




    there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
    – Jeff Schaller
    1 hour ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have two different files separated by Tab. File 1 looks like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YMR325W 6.2822794040082 6.46992587787936 7.00507748994596


File 2 looks like this:



YLR177W 11.321823973245 12.1264440368589    11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998


What I'm trying to do right now is to add 10 lines from File 2 to File 1 after 2 lines. It should look like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
YLR177W 11.321823973245 12.1264440368589 11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405


So, basically, I'm trying to move 10 lines from File 2 between each transcr_ keeping the already existent line that is already below each transcr_.










share|improve this question









New contributor




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











I have two different files separated by Tab. File 1 looks like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YMR325W 6.2822794040082 6.46992587787936 7.00507748994596


File 2 looks like this:



YLR177W 11.321823973245 12.1264440368589    11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998


What I'm trying to do right now is to add 10 lines from File 2 to File 1 after 2 lines. It should look like this:



transcr_15824   3.95253441295071    3.99992738843234    3.93880798313547
YML042W 10.3143219248979 10.6898819949325 11.0073811719421
YLR177W 11.321823973245 12.1264440368589 11.7777091957438
YOR117W 10.7514234580732 11.3932687209745 11.2587694561818
TY_120 5.95114867088525 5.93580053538449 5.89166059690558
YMR174C 8.49545850099485 8.72467418433346 9.6518559706269
YPL117C 10.7211879012765 10.5046713289602 10.6145538571844
TY2_LTR_77 11.9297940548212 11.9801206538102 12.049127298122
YOL101C 7.76141097131674 9.89522697916433 7.85466704627526
YLR053C 7.62843998411388 7.49205634213499 7.10263942962051
YBR135W 9.70614244227352 9.3114074341804 9.36413815370247
YNL168C 9.93928326709444 10.3036524361223 10.0704544058998
transcr_18545 7.76182774638543 7.25508954643215 7.92562682485731
YCR105W 8.46144110056843 8.30995100411912 8.85470858413405


So, basically, I'm trying to move 10 lines from File 2 between each transcr_ keeping the already existent line that is already below each transcr_.







text-processing






share|improve this question









New contributor




Lucas Farinazzo Marques 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




Lucas Farinazzo Marques 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 1 hour ago









Rui F Ribeiro

38.5k1479128




38.5k1479128






New contributor




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









asked 2 hours ago









Lucas Farinazzo Marques

161




161




New contributor




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





New contributor





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






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












  • Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
    – fra-san
    1 hour ago






  • 1




    there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
    – Jeff Schaller
    1 hour ago


















  • Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
    – fra-san
    1 hour ago






  • 1




    there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
    – Jeff Schaller
    1 hour ago
















Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
– fra-san
1 hour ago




Welcome on U&L! Have you got only two files, or more files like File 2 to be merged into File 1? Should the whole content of File 2 be added to File 1? Or a part of it only? Should the content of File 2 be added after a specific occurrence of transcr_, or after all of them?
– fra-san
1 hour ago




1




1




there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
– Jeff Schaller
1 hour ago




there are three "transcr_" lines in file1; do you want the same 10 lines from file2 after each of those transcr_ lines, or ... subsequent 10 lines from file2 each time, or ???
– Jeff Schaller
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
6
down vote













You could use ed!



ed -s file1 <<< $'2r !head -10 file2nwnq'


This tells ed to edit file1 with three commands:




  1. on line 2, read in the output of the command head -10 file2 and insert it


  2. write the file out


  3. quit ed


With GNU sed (using the e extension, which pipes input from a shell command):



sed -i '3e head -10 file2' file1





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


    }
    });






    Lucas Farinazzo Marques 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%2f487764%2fhow-can-i-add-10-lines-from-a-file-file2-to-another-one-after-2-lines-file1%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    6
    down vote













    You could use ed!



    ed -s file1 <<< $'2r !head -10 file2nwnq'


    This tells ed to edit file1 with three commands:




    1. on line 2, read in the output of the command head -10 file2 and insert it


    2. write the file out


    3. quit ed


    With GNU sed (using the e extension, which pipes input from a shell command):



    sed -i '3e head -10 file2' file1





    share|improve this answer



























      up vote
      6
      down vote













      You could use ed!



      ed -s file1 <<< $'2r !head -10 file2nwnq'


      This tells ed to edit file1 with three commands:




      1. on line 2, read in the output of the command head -10 file2 and insert it


      2. write the file out


      3. quit ed


      With GNU sed (using the e extension, which pipes input from a shell command):



      sed -i '3e head -10 file2' file1





      share|improve this answer

























        up vote
        6
        down vote










        up vote
        6
        down vote









        You could use ed!



        ed -s file1 <<< $'2r !head -10 file2nwnq'


        This tells ed to edit file1 with three commands:




        1. on line 2, read in the output of the command head -10 file2 and insert it


        2. write the file out


        3. quit ed


        With GNU sed (using the e extension, which pipes input from a shell command):



        sed -i '3e head -10 file2' file1





        share|improve this answer














        You could use ed!



        ed -s file1 <<< $'2r !head -10 file2nwnq'


        This tells ed to edit file1 with three commands:




        1. on line 2, read in the output of the command head -10 file2 and insert it


        2. write the file out


        3. quit ed


        With GNU sed (using the e extension, which pipes input from a shell command):



        sed -i '3e head -10 file2' file1






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago

























        answered 1 hour ago









        Jeff Schaller

        37.7k1052121




        37.7k1052121






















            Lucas Farinazzo Marques is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Lucas Farinazzo Marques is a new contributor. Be nice, and check out our Code of Conduct.













            Lucas Farinazzo Marques is a new contributor. Be nice, and check out our Code of Conduct.












            Lucas Farinazzo Marques is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f487764%2fhow-can-i-add-10-lines-from-a-file-file2-to-another-one-after-2-lines-file1%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

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu