Community
    • Login

    search and replace a set of texts

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 763 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nagoor Meerasa MohammedN Offline
      Nagoor Meerasa Mohammed
      last edited by

      Hi

      I am looking to search and replace a set of text like

      File 1 has the below text

      3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003)

      File 2 has this

      1 Phalera_flavescens
      2 Ochrogaster_lunifer
      3 Hyphantria_cunea
      4 Eudocima_salaminia
      5 Eudocima_phalonia
      6 Grammodes_geometrica
      7 Parallelia_stuposa

      Now in File1 I have to replace “1:” with “Phalera_flavescens:” that is I have to replace 1 with Phalera_flavescens but not in all places but only at place i have the number followed by colon. Same way I have to replace “2:” with “Ochrogaster_lunifer:” and so on.

      Thanks

      1 Reply Last reply Reply Quote 0
      • guy038G Offline
        guy038
        last edited by

        Hello, @nagoor-meerasa-mohammed, and All,

        Well, you’ve provided very few information ! Your example is just a long one-line text which contains 15 zones with a number followed with a colon, listed below, in reading order :

        3:
        64:
        4:
        5:
        92:
        7:
        62:
        6:
        7:
        2:
        91:
        2:
        6:
        5:
        1:
        

        Do you speak of all these numbers ?

        If so, I suppose that your File 2 text should contain, at least, 92 items ?

        Have a look, first, to this post :

        https://community.notepad-plus-plus.org/topic/21965/please-read-before-posting

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 1
        • Nagoor Meerasa MohammedN Offline
          Nagoor Meerasa Mohammed
          last edited by

          @nagoor-meerasa-mohammed said in search and replace a set of texts:

          :

          Hi guy038, Thanks for the reply. what you assumed is correct. I have posted only few lines because the full file is very large and is of not much use.

          1 Reply Last reply Reply Quote 0
          • guy038G Offline
            guy038
            last edited by

            Hi, @nagoor-meerasa-mohammed, and All,

            OK ! So, here is the road map :

            • Copy all the File 1.txt contents in, let’s say, a file named File 3.txt

            • Add a separation line of, at least, three = signs

            • Append all the File 2.txt contents, after the separation line

            • Open the Replace dialog ( Ctrl + F )

              • SEARCH (?-s)\D\K(\d+):(?=(?s:.+^=+\R.*^\1\x20)(.+))|^===+(?s).+

              • REPLACE ?1\2

              • Tick the Wrap around option

              • Select the Regular expression search mode

              • Click only on the Replace All button ( Do not use the Replace button ! )

            • Close the Replace dialog ( Esc )

            • Save the File 3.txt modifications ( Ctrl + S )


            Here is an example where I copied your File 1.txt text, twice, then the separation line ===== and, finally your File 2.txt text

            3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003)
            
            3:1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((4:7.719304e-002,5:7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(7:1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((6:9.872749e-002,7:7.750112e-002):3.270381e-002,(2:1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(2:2.990773e-001,((((((6:7.144297e-002,((5:3.452890e-002,1:7.746965e-003)
            =====
            
            1 Phalera_flavescens
            2 Ochrogaster_lunifer
            3 Hyphantria_cunea
            4 Eudocima_salaminia
            5 Eudocima_phalonia
            6 Grammodes_geometrica
            7 Parallelia_stuposa
            

            AFter clicking on the Replace All button, you should get this new text :

            Hyphantria_cunea1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((Eudocima_salaminia7.719304e-002,Eudocima_phalonia7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(Parallelia_stuposa1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((Grammodes_geometrica9.872749e-002,Parallelia_stuposa7.750112e-002):3.270381e-002,(Ochrogaster_lunifer1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(Ochrogaster_lunifer2.990773e-001,((((((Grammodes_geometrica7.144297e-002,((Eudocima_phalonia3.452890e-002,Phalera_flavescens7.746965e-003)
            
            Hyphantria_cunea1.428238e-001):4.577779e-002,64:9.743924e-002):7.427767e-002):2.922571e-002):3.206583e-002,((((Eudocima_salaminia7.719304e-002,Eudocima_phalonia7.767254e-002):9.925778e-002,92:1.697033e-001):2.906791e-002,(Parallelia_stuposa1.281314e-001,62:1.351362e-001):2.747034e-002):1.246730e-002,((Grammodes_geometrica9.872749e-002,Parallelia_stuposa7.750112e-002):3.270381e-002,(Ochrogaster_lunifer1.533366e-001,91:1.316264e-001):2.139538e-002):5.698094e-002):3.332409e-002):5.389512e-002,(Ochrogaster_lunifer2.990773e-001,((((((Grammodes_geometrica7.144297e-002,((Eudocima_phalonia3.452890e-002,Phalera_flavescens7.746965e-003)
            

            Notes :

            • The File 2.txt list of items, at the end of File 3.txt, has been deleted, too !

            • Of course, any number followed with a colon, which does not exist in the list, located after the separation line =====, is not replaced at all, in the section before the ===== line

            • The File 2.txt list of items, at the end of File 3.txt, do not need to be sorted, too !

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors