Replacing lines in one file based of indices in a second fileUsing AWK for loop as input for find and...

Cheap storage lockers in Tromsø, Norway

Are there categories whose internal hom is somewhat 'exotic'?

Using は before 欲しい instead が

What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?

E: Sub-process /usr/bin/dpkg returned an error code (1) - but how do I find the meaningful error messages in APT's output?

Would it be illegal for Facebook to actively promote a political agenda?

Is this kind of description not recommended?

How does the Saturn V Dynamic Test Stand work?

Sous vide chicken without an internal tempature of 165

Can 'in-' mean both 'in' and 'no'?

Why don't sharp and flat root note chords seem to be present in much guitar music?

!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!

Default camera device to show screen instead of physical camera

How to think about joining a company whose business I do not understand?

Nuclear decay triggers

How can I pack my food so it doesn't smell?

Chess software to analyze games

Land Registry Clause

Are objects subject to critical hits?

Could sidesticks be linked?

Why should someone be willing to write a strong recommendation even if that means losing a undergraduate from their lab?

Does git delete empty folders?

In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?

Are there any OR challenges that are similar to kaggle's competitions?



Replacing lines in one file based of indices in a second file


Using AWK for loop as input for find and replaceReplacing lines containing a pattern with sedSingle record of a file getting splitted over multiple linesParse header in a file and based on the header replace a value in the fileExtracting lines based on conditionsUsing awk to combine two csv files on three fields too create a new csv filereplacing values in one with the values in another fileHow to split a file into paragraphs and name the resulting pieces based on an identifier present in each paragraphReplacing Line if it Matches Line from Other File in Nested [While, IF, Sed] StatementReplace odd lines in one text file with the corresponding odd lines in another text file using sed/awk/etcUsing AWK for loop as input for find and replace






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have two files:



Ref.txt which contains:



ABCDEFG,15147,1,2,6
HIJKLMN,500,3,4


and Seq.txt which contains:



ABCXXXX
ABCDEXX
IIJKXXX
HIHKXXX
LMNOPQR
BBCDEXX
STUVWXY


I would like to replace the certain lines in the Seq.txt file. The indices of the lines that should be replaces are listed in fields 3-end of Ref.txt file, and what the lines should be replaced with is located in field 1 of the same line in the Ref.txt file. The output I am looking for in this example is this:



ABCDEFG
ABCDEFG
HIJKLMN
HIJKLMN
LMNOPQR
ABCDEFG
STUVWXY









share|improve this question







New contributor



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




























    0















    I have two files:



    Ref.txt which contains:



    ABCDEFG,15147,1,2,6
    HIJKLMN,500,3,4


    and Seq.txt which contains:



    ABCXXXX
    ABCDEXX
    IIJKXXX
    HIHKXXX
    LMNOPQR
    BBCDEXX
    STUVWXY


    I would like to replace the certain lines in the Seq.txt file. The indices of the lines that should be replaces are listed in fields 3-end of Ref.txt file, and what the lines should be replaced with is located in field 1 of the same line in the Ref.txt file. The output I am looking for in this example is this:



    ABCDEFG
    ABCDEFG
    HIJKLMN
    HIJKLMN
    LMNOPQR
    ABCDEFG
    STUVWXY









    share|improve this question







    New contributor



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
























      0












      0








      0








      I have two files:



      Ref.txt which contains:



      ABCDEFG,15147,1,2,6
      HIJKLMN,500,3,4


      and Seq.txt which contains:



      ABCXXXX
      ABCDEXX
      IIJKXXX
      HIHKXXX
      LMNOPQR
      BBCDEXX
      STUVWXY


      I would like to replace the certain lines in the Seq.txt file. The indices of the lines that should be replaces are listed in fields 3-end of Ref.txt file, and what the lines should be replaced with is located in field 1 of the same line in the Ref.txt file. The output I am looking for in this example is this:



      ABCDEFG
      ABCDEFG
      HIJKLMN
      HIJKLMN
      LMNOPQR
      ABCDEFG
      STUVWXY









      share|improve this question







      New contributor



      DNA_bash 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 files:



      Ref.txt which contains:



      ABCDEFG,15147,1,2,6
      HIJKLMN,500,3,4


      and Seq.txt which contains:



      ABCXXXX
      ABCDEXX
      IIJKXXX
      HIHKXXX
      LMNOPQR
      BBCDEXX
      STUVWXY


      I would like to replace the certain lines in the Seq.txt file. The indices of the lines that should be replaces are listed in fields 3-end of Ref.txt file, and what the lines should be replaced with is located in field 1 of the same line in the Ref.txt file. The output I am looking for in this example is this:



      ABCDEFG
      ABCDEFG
      HIJKLMN
      HIJKLMN
      LMNOPQR
      ABCDEFG
      STUVWXY






      awk sed files osx string






      share|improve this question







      New contributor



      DNA_bash 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



      DNA_bash 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






      New contributor



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








      asked 2 days ago









      DNA_bashDNA_bash

      273 bronze badges




      273 bronze badges




      New contributor



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




      New contributor




      DNA_bash 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


















          2














          awk -F, '
          NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next}
          FNR in a {$0 = a[FNR]}
          1
          ' Ref.txt Seq.txt
          ABCDEFG
          ABCDEFG
          HIJKLMN
          HIJKLMN
          LMNOPQR
          ABCDEFG
          STUVWXY





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


            }
            });






            DNA_bash 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%2f535927%2freplacing-lines-in-one-file-based-of-indices-in-a-second-file%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









            2














            awk -F, '
            NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next}
            FNR in a {$0 = a[FNR]}
            1
            ' Ref.txt Seq.txt
            ABCDEFG
            ABCDEFG
            HIJKLMN
            HIJKLMN
            LMNOPQR
            ABCDEFG
            STUVWXY





            share|improve this answer






























              2














              awk -F, '
              NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next}
              FNR in a {$0 = a[FNR]}
              1
              ' Ref.txt Seq.txt
              ABCDEFG
              ABCDEFG
              HIJKLMN
              HIJKLMN
              LMNOPQR
              ABCDEFG
              STUVWXY





              share|improve this answer




























                2












                2








                2







                awk -F, '
                NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next}
                FNR in a {$0 = a[FNR]}
                1
                ' Ref.txt Seq.txt
                ABCDEFG
                ABCDEFG
                HIJKLMN
                HIJKLMN
                LMNOPQR
                ABCDEFG
                STUVWXY





                share|improve this answer













                awk -F, '
                NR==FNR {for(i=3;i<=NF;i++) a[$i] = $1; next}
                FNR in a {$0 = a[FNR]}
                1
                ' Ref.txt Seq.txt
                ABCDEFG
                ABCDEFG
                HIJKLMN
                HIJKLMN
                LMNOPQR
                ABCDEFG
                STUVWXY






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                steeldriversteeldriver

                42.2k5 gold badges56 silver badges94 bronze badges




                42.2k5 gold badges56 silver badges94 bronze badges

























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










                    draft saved

                    draft discarded


















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













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












                    DNA_bash 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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535927%2freplacing-lines-in-one-file-based-of-indices-in-a-second-file%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

                    Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                    The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                    Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...